mirror of
https://github.com/pawelorzech/AddToObsidian.git
synced 2026-01-29 19:54:30 +00:00
Add macOS menu bar app for quick Obsidian notes
- Menu bar app with global hotkey (⌃⌥⌘O) to capture notes - Notes saved as Markdown with YAML frontmatter - File naming: yyyy-MM-dd_HH-mm-ss.md - Settings view for Obsidian vault folder selection - Carbon API for global keyboard shortcut registration - Security-scoped bookmarks for persistent folder access
This commit is contained in:
parent
0a26d0313a
commit
6df94cd7fd
18 changed files with 1295 additions and 56 deletions
78
.gitignore
vendored
78
.gitignore
vendored
|
|
@ -1,62 +1,30 @@
|
|||
# Xcode
|
||||
#
|
||||
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
|
||||
|
||||
## User settings
|
||||
build/
|
||||
*.xcuserstate
|
||||
*.xcuserdatad
|
||||
*.xcworkspace/xcuserdata/
|
||||
DerivedData/
|
||||
*.moved-aside
|
||||
*.pbxuser
|
||||
!default.pbxuser
|
||||
*.mode1v3
|
||||
!default.mode1v3
|
||||
*.mode2v3
|
||||
!default.mode2v3
|
||||
*.perspectivev3
|
||||
!default.perspectivev3
|
||||
xcuserdata/
|
||||
|
||||
## Obj-C/Swift specific
|
||||
*.hmap
|
||||
|
||||
## App packaging
|
||||
*.ipa
|
||||
*.dSYM.zip
|
||||
*.dSYM
|
||||
|
||||
## Playgrounds
|
||||
timeline.xctimeline
|
||||
playground.xcworkspace
|
||||
|
||||
# Swift Package Manager
|
||||
#
|
||||
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
|
||||
# Packages/
|
||||
# Package.pins
|
||||
# Package.resolved
|
||||
# *.xcodeproj
|
||||
#
|
||||
# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata
|
||||
# hence it is not needed unless you have added a package configuration file to your project
|
||||
# .swiftpm
|
||||
|
||||
.build/
|
||||
.swiftpm/
|
||||
|
||||
# CocoaPods
|
||||
#
|
||||
# We recommend against adding the Pods directory to your .gitignore. However
|
||||
# you should judge for yourself, the pros and cons are mentioned at:
|
||||
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
||||
#
|
||||
# Pods/
|
||||
#
|
||||
# Add this line if you want to avoid checking in source code from the Xcode workspace
|
||||
# *.xcworkspace
|
||||
# macOS
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
._*
|
||||
|
||||
# Carthage
|
||||
#
|
||||
# Add this line if you want to avoid checking in source code from Carthage dependencies.
|
||||
# Carthage/Checkouts
|
||||
|
||||
Carthage/Build/
|
||||
|
||||
# fastlane
|
||||
#
|
||||
# It is recommended to not store the screenshots in the git repo.
|
||||
# Instead, use fastlane to re-generate the screenshots whenever they are needed.
|
||||
# For more information about the recommended setup visit:
|
||||
# https://docs.fastlane.tools/best-practices/source-control/#source-control
|
||||
|
||||
fastlane/report.xml
|
||||
fastlane/Preview.html
|
||||
fastlane/screenshots/**/*.png
|
||||
fastlane/test_output
|
||||
# Temporary files
|
||||
*.swp
|
||||
*~
|
||||
|
|
|
|||
422
AddToObsidian.xcodeproj/project.pbxproj
Normal file
422
AddToObsidian.xcodeproj/project.pbxproj
Normal file
|
|
@ -0,0 +1,422 @@
|
|||
// !$*UTF8*$!
|
||||
{
|
||||
archiveVersion = 1;
|
||||
classes = {
|
||||
};
|
||||
objectVersion = 56;
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
A10000010000000000000001 /* AddToObsidianApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = A20000010000000000000001 /* AddToObsidianApp.swift */; };
|
||||
A10000010000000000000002 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A20000010000000000000002 /* AppDelegate.swift */; };
|
||||
A10000010000000000000003 /* NoteInputView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A20000010000000000000003 /* NoteInputView.swift */; };
|
||||
A10000010000000000000004 /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A20000010000000000000004 /* SettingsView.swift */; };
|
||||
A10000010000000000000005 /* NoteViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A20000010000000000000005 /* NoteViewModel.swift */; };
|
||||
A10000010000000000000006 /* HotKeyManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A20000010000000000000006 /* HotKeyManager.swift */; };
|
||||
A10000010000000000000007 /* NoteFileService.swift in Sources */ = {isa = PBXBuildFile; fileRef = A20000010000000000000007 /* NoteFileService.swift */; };
|
||||
A10000010000000000000008 /* SettingsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A20000010000000000000008 /* SettingsManager.swift */; };
|
||||
A10000010000000000000009 /* Note.swift in Sources */ = {isa = PBXBuildFile; fileRef = A20000010000000000000009 /* Note.swift */; };
|
||||
A10000010000000000000010 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A20000010000000000000010 /* Assets.xcassets */; };
|
||||
A10000010000000000000011 /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A20000010000000000000011 /* Carbon.framework */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
A20000010000000000000001 /* AddToObsidianApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddToObsidianApp.swift; sourceTree = "<group>"; };
|
||||
A20000010000000000000002 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||
A20000010000000000000003 /* NoteInputView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoteInputView.swift; sourceTree = "<group>"; };
|
||||
A20000010000000000000004 /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
|
||||
A20000010000000000000005 /* NoteViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoteViewModel.swift; sourceTree = "<group>"; };
|
||||
A20000010000000000000006 /* HotKeyManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HotKeyManager.swift; sourceTree = "<group>"; };
|
||||
A20000010000000000000007 /* NoteFileService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoteFileService.swift; sourceTree = "<group>"; };
|
||||
A20000010000000000000008 /* SettingsManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsManager.swift; sourceTree = "<group>"; };
|
||||
A20000010000000000000009 /* Note.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Note.swift; sourceTree = "<group>"; };
|
||||
A20000010000000000000010 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||
A20000010000000000000011 /* Carbon.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Carbon.framework; path = System/Library/Frameworks/Carbon.framework; sourceTree = SDKROOT; };
|
||||
A20000010000000000000012 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
A20000010000000000000013 /* AddToObsidian.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = AddToObsidian.entitlements; sourceTree = "<group>"; };
|
||||
A30000010000000000000001 /* AddToObsidian.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AddToObsidian.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
A40000010000000000000001 /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
A10000010000000000000011 /* Carbon.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXFrameworksBuildPhase section */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
A50000010000000000000001 = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
A50000010000000000000002 /* AddToObsidian */,
|
||||
A50000010000000000000007 /* Frameworks */,
|
||||
A50000010000000000000008 /* Products */,
|
||||
);
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
A50000010000000000000002 /* AddToObsidian */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
A50000010000000000000003 /* App */,
|
||||
A50000010000000000000004 /* Views */,
|
||||
A50000010000000000000005 /* ViewModels */,
|
||||
A50000010000000000000006 /* Services */,
|
||||
A50000010000000000000009 /* Models */,
|
||||
A50000010000000000000010 /* Resources */,
|
||||
);
|
||||
path = AddToObsidian;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
A50000010000000000000003 /* App */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
A20000010000000000000001 /* AddToObsidianApp.swift */,
|
||||
A20000010000000000000002 /* AppDelegate.swift */,
|
||||
);
|
||||
path = App;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
A50000010000000000000004 /* Views */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
A20000010000000000000003 /* NoteInputView.swift */,
|
||||
A20000010000000000000004 /* SettingsView.swift */,
|
||||
);
|
||||
path = Views;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
A50000010000000000000005 /* ViewModels */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
A20000010000000000000005 /* NoteViewModel.swift */,
|
||||
);
|
||||
path = ViewModels;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
A50000010000000000000006 /* Services */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
A20000010000000000000006 /* HotKeyManager.swift */,
|
||||
A20000010000000000000007 /* NoteFileService.swift */,
|
||||
A20000010000000000000008 /* SettingsManager.swift */,
|
||||
);
|
||||
path = Services;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
A50000010000000000000007 /* Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
A20000010000000000000011 /* Carbon.framework */,
|
||||
);
|
||||
name = Frameworks;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
A50000010000000000000008 /* Products */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
A30000010000000000000001 /* AddToObsidian.app */,
|
||||
);
|
||||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
A50000010000000000000009 /* Models */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
A20000010000000000000009 /* Note.swift */,
|
||||
);
|
||||
path = Models;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
A50000010000000000000010 /* Resources */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
A20000010000000000000010 /* Assets.xcassets */,
|
||||
A20000010000000000000012 /* Info.plist */,
|
||||
A20000010000000000000013 /* AddToObsidian.entitlements */,
|
||||
);
|
||||
path = Resources;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
A60000010000000000000001 /* AddToObsidian */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = A80000010000000000000001 /* Build configuration list for PBXNativeTarget "AddToObsidian" */;
|
||||
buildPhases = (
|
||||
A60000010000000000000002 /* Sources */,
|
||||
A40000010000000000000001 /* Frameworks */,
|
||||
A60000010000000000000003 /* Resources */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
dependencies = (
|
||||
);
|
||||
name = AddToObsidian;
|
||||
productName = AddToObsidian;
|
||||
productReference = A30000010000000000000001 /* AddToObsidian.app */;
|
||||
productType = "com.apple.product-type.application";
|
||||
};
|
||||
/* End PBXNativeTarget section */
|
||||
|
||||
/* Begin PBXProject section */
|
||||
A70000010000000000000001 /* Project object */ = {
|
||||
isa = PBXProject;
|
||||
attributes = {
|
||||
BuildIndependentTargetsInParallel = 1;
|
||||
LastSwiftUpdateCheck = 1500;
|
||||
LastUpgradeCheck = 1500;
|
||||
TargetAttributes = {
|
||||
A60000010000000000000001 = {
|
||||
CreatedOnToolsVersion = 15.0;
|
||||
};
|
||||
};
|
||||
};
|
||||
buildConfigurationList = A80000010000000000000002 /* Build configuration list for PBXProject "AddToObsidian" */;
|
||||
compatibilityVersion = "Xcode 14.0";
|
||||
developmentRegion = en;
|
||||
hasScannedForEncodings = 0;
|
||||
knownRegions = (
|
||||
en,
|
||||
Base,
|
||||
);
|
||||
mainGroup = A50000010000000000000001;
|
||||
productRefGroup = A50000010000000000000008 /* Products */;
|
||||
projectDirPath = "";
|
||||
projectRoot = "";
|
||||
targets = (
|
||||
A60000010000000000000001 /* AddToObsidian */,
|
||||
);
|
||||
};
|
||||
/* End PBXProject section */
|
||||
|
||||
/* Begin PBXResourcesBuildPhase section */
|
||||
A60000010000000000000003 /* Resources */ = {
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
A10000010000000000000010 /* Assets.xcassets in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXResourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXSourcesBuildPhase section */
|
||||
A60000010000000000000002 /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
A10000010000000000000001 /* AddToObsidianApp.swift in Sources */,
|
||||
A10000010000000000000002 /* AppDelegate.swift in Sources */,
|
||||
A10000010000000000000003 /* NoteInputView.swift in Sources */,
|
||||
A10000010000000000000004 /* SettingsView.swift in Sources */,
|
||||
A10000010000000000000005 /* NoteViewModel.swift in Sources */,
|
||||
A10000010000000000000006 /* HotKeyManager.swift in Sources */,
|
||||
A10000010000000000000007 /* NoteFileService.swift in Sources */,
|
||||
A10000010000000000000008 /* SettingsManager.swift in Sources */,
|
||||
A10000010000000000000009 /* Note.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXSourcesBuildPhase section */
|
||||
|
||||
/* Begin XCBuildConfiguration section */
|
||||
A90000010000000000000001 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
|
||||
CLANG_ANALYZER_NONNULL = YES;
|
||||
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
CLANG_ENABLE_OBJC_WEAK = YES;
|
||||
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_COMMA = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
|
||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
|
||||
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
|
||||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
||||
CLANG_WARN_STRICT_PROTOTYPES = YES;
|
||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
COPY_PHASE_STRIP = NO;
|
||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
ENABLE_TESTABILITY = YES;
|
||||
ENABLE_USER_SCRIPT_SANDBOXING = YES;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu17;
|
||||
GCC_DYNAMIC_NO_PIC = NO;
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
GCC_OPTIMIZATION_LEVEL = 0;
|
||||
GCC_PREPROCESSOR_DEFINITIONS = (
|
||||
"DEBUG=1",
|
||||
"$(inherited)",
|
||||
);
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
||||
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
MACOSX_DEPLOYMENT_TARGET = 13.0;
|
||||
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
|
||||
MTL_FAST_MATH = YES;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
SDKROOT = macosx;
|
||||
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)";
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
A90000010000000000000002 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
|
||||
CLANG_ANALYZER_NONNULL = YES;
|
||||
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
CLANG_ENABLE_OBJC_WEAK = YES;
|
||||
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_COMMA = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
|
||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
|
||||
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
|
||||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
||||
CLANG_WARN_STRICT_PROTOTYPES = YES;
|
||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
COPY_PHASE_STRIP = NO;
|
||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
||||
ENABLE_NS_ASSERTIONS = NO;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
ENABLE_USER_SCRIPT_SANDBOXING = YES;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu17;
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
||||
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
MACOSX_DEPLOYMENT_TARGET = 13.0;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
MTL_FAST_MATH = YES;
|
||||
SDKROOT = macosx;
|
||||
SWIFT_COMPILATION_MODE = wholemodule;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
A90000010000000000000003 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
||||
CODE_SIGN_ENTITLEMENTS = AddToObsidian/Resources/AddToObsidian.entitlements;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
DEVELOPMENT_TEAM = "";
|
||||
ENABLE_HARDENED_RUNTIME = YES;
|
||||
GENERATE_INFOPLIST_FILE = NO;
|
||||
INFOPLIST_FILE = AddToObsidian/Resources/Info.plist;
|
||||
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.productivity";
|
||||
INFOPLIST_KEY_NSHumanReadableCopyright = "";
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/../Frameworks",
|
||||
);
|
||||
MARKETING_VERSION = 1.0;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.yourname.AddToObsidian;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||
SWIFT_VERSION = 5.0;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
A90000010000000000000004 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
||||
CODE_SIGN_ENTITLEMENTS = AddToObsidian/Resources/AddToObsidian.entitlements;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
DEVELOPMENT_TEAM = "";
|
||||
ENABLE_HARDENED_RUNTIME = YES;
|
||||
GENERATE_INFOPLIST_FILE = NO;
|
||||
INFOPLIST_FILE = AddToObsidian/Resources/Info.plist;
|
||||
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.productivity";
|
||||
INFOPLIST_KEY_NSHumanReadableCopyright = "";
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/../Frameworks",
|
||||
);
|
||||
MARKETING_VERSION = 1.0;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.yourname.AddToObsidian;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||
SWIFT_VERSION = 5.0;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
/* End XCBuildConfiguration section */
|
||||
|
||||
/* Begin XCConfigurationList section */
|
||||
A80000010000000000000001 /* Build configuration list for PBXNativeTarget "AddToObsidian" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
A90000010000000000000003 /* Debug */,
|
||||
A90000010000000000000004 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
A80000010000000000000002 /* Build configuration list for PBXProject "AddToObsidian" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
A90000010000000000000001 /* Debug */,
|
||||
A90000010000000000000002 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
/* End XCConfigurationList section */
|
||||
};
|
||||
rootObject = A70000010000000000000001 /* Project object */;
|
||||
}
|
||||
12
AddToObsidian/App/AddToObsidianApp.swift
Normal file
12
AddToObsidian/App/AddToObsidianApp.swift
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import SwiftUI
|
||||
|
||||
@main
|
||||
struct AddToObsidianApp: App {
|
||||
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
|
||||
|
||||
var body: some Scene {
|
||||
Settings {
|
||||
SettingsView()
|
||||
}
|
||||
}
|
||||
}
|
||||
144
AddToObsidian/App/AppDelegate.swift
Normal file
144
AddToObsidian/App/AppDelegate.swift
Normal file
|
|
@ -0,0 +1,144 @@
|
|||
import AppKit
|
||||
import SwiftUI
|
||||
|
||||
class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
private var statusItem: NSStatusItem?
|
||||
private var notePanel: NSPanel?
|
||||
private var noteViewModel = NoteViewModel()
|
||||
private let hotKeyManager = HotKeyManager.shared
|
||||
|
||||
func applicationDidFinishLaunching(_ notification: Notification) {
|
||||
// Hide from Dock
|
||||
NSApp.setActivationPolicy(.accessory)
|
||||
|
||||
// Setup menu bar
|
||||
setupStatusItem()
|
||||
|
||||
// Register global hotkey
|
||||
hotKeyManager.register { [weak self] in
|
||||
self?.showNotePanel()
|
||||
}
|
||||
|
||||
print("AddToObsidian started. Press Control + Option + Cmd + O to add a note.")
|
||||
}
|
||||
|
||||
private func setupStatusItem() {
|
||||
statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
|
||||
|
||||
if let button = statusItem?.button {
|
||||
button.image = NSImage(systemSymbolName: "note.text.badge.plus", accessibilityDescription: "Add to Obsidian")
|
||||
button.action = #selector(statusItemClicked)
|
||||
button.target = self
|
||||
button.sendAction(on: [.leftMouseUp, .rightMouseUp])
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func statusItemClicked(_ sender: NSStatusBarButton) {
|
||||
guard let event = NSApp.currentEvent else { return }
|
||||
|
||||
if event.type == .rightMouseUp {
|
||||
showMenu()
|
||||
} else {
|
||||
showNotePanel()
|
||||
}
|
||||
}
|
||||
|
||||
private func showMenu() {
|
||||
let menu = NSMenu()
|
||||
|
||||
menu.addItem(NSMenuItem(title: "Add Note (⌃⌥⌘O)", action: #selector(showNotePanelAction), keyEquivalent: ""))
|
||||
menu.addItem(NSMenuItem.separator())
|
||||
menu.addItem(NSMenuItem(title: "Settings...", action: #selector(showSettings), keyEquivalent: ","))
|
||||
menu.addItem(NSMenuItem.separator())
|
||||
menu.addItem(NSMenuItem(title: "Quit AddToObsidian", action: #selector(quitApp), keyEquivalent: "q"))
|
||||
|
||||
statusItem?.menu = menu
|
||||
statusItem?.button?.performClick(nil)
|
||||
statusItem?.menu = nil
|
||||
}
|
||||
|
||||
@objc private func showNotePanelAction() {
|
||||
showNotePanel()
|
||||
}
|
||||
|
||||
func showNotePanel() {
|
||||
if notePanel == nil {
|
||||
createNotePanel()
|
||||
}
|
||||
|
||||
noteViewModel.clearNote()
|
||||
|
||||
guard let panel = notePanel else { return }
|
||||
|
||||
// Center the panel on screen
|
||||
if let screen = NSScreen.main {
|
||||
let screenFrame = screen.visibleFrame
|
||||
let panelSize = panel.frame.size
|
||||
let x = screenFrame.midX - panelSize.width / 2
|
||||
let y = screenFrame.midY - panelSize.height / 2
|
||||
panel.setFrameOrigin(NSPoint(x: x, y: y))
|
||||
}
|
||||
|
||||
panel.makeKeyAndOrderFront(nil)
|
||||
NSApp.activate(ignoringOtherApps: true)
|
||||
}
|
||||
|
||||
private func createNotePanel() {
|
||||
let panel = NSPanel(
|
||||
contentRect: NSRect(x: 0, y: 0, width: 400, height: 280),
|
||||
styleMask: [.titled, .closable, .nonactivatingPanel, .fullSizeContentView],
|
||||
backing: .buffered,
|
||||
defer: false
|
||||
)
|
||||
|
||||
panel.level = .floating
|
||||
panel.isFloatingPanel = true
|
||||
panel.hidesOnDeactivate = false
|
||||
panel.titleVisibility = .hidden
|
||||
panel.titlebarAppearsTransparent = true
|
||||
panel.isMovableByWindowBackground = true
|
||||
panel.backgroundColor = .clear
|
||||
|
||||
let contentView = NoteInputView(
|
||||
viewModel: noteViewModel,
|
||||
onSave: { [weak self] in
|
||||
self?.hideNotePanel()
|
||||
},
|
||||
onCancel: { [weak self] in
|
||||
self?.hideNotePanel()
|
||||
}
|
||||
)
|
||||
|
||||
panel.contentView = NSHostingView(rootView: contentView)
|
||||
|
||||
self.notePanel = panel
|
||||
}
|
||||
|
||||
private func hideNotePanel() {
|
||||
notePanel?.orderOut(nil)
|
||||
}
|
||||
|
||||
@objc private func showSettings() {
|
||||
NSApp.sendAction(Selector(("showSettingsWindow:")), to: nil, from: nil)
|
||||
|
||||
// Fallback: open settings window manually
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
|
||||
for window in NSApp.windows {
|
||||
if window.title.contains("Settings") || window.title.contains("Preferences") {
|
||||
window.makeKeyAndOrderFront(nil)
|
||||
NSApp.activate(ignoringOtherApps: true)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func quitApp() {
|
||||
hotKeyManager.unregister()
|
||||
NSApp.terminate(nil)
|
||||
}
|
||||
|
||||
func applicationWillTerminate(_ notification: Notification) {
|
||||
hotKeyManager.unregister()
|
||||
}
|
||||
}
|
||||
34
AddToObsidian/Models/Note.swift
Normal file
34
AddToObsidian/Models/Note.swift
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import Foundation
|
||||
|
||||
struct Note {
|
||||
let content: String
|
||||
let createdAt: Date
|
||||
|
||||
init(content: String, createdAt: Date = Date()) {
|
||||
self.content = content
|
||||
self.createdAt = createdAt
|
||||
}
|
||||
|
||||
var filename: String {
|
||||
let formatter = DateFormatter()
|
||||
formatter.dateFormat = "yyyy-MM-dd_HH-mm-ss"
|
||||
return "\(formatter.string(from: createdAt)).md"
|
||||
}
|
||||
|
||||
var frontmatter: String {
|
||||
let isoFormatter = ISO8601DateFormatter()
|
||||
isoFormatter.formatOptions = [.withInternetDateTime]
|
||||
let dateString = isoFormatter.string(from: createdAt)
|
||||
|
||||
return """
|
||||
---
|
||||
created: \(dateString)
|
||||
---
|
||||
|
||||
"""
|
||||
}
|
||||
|
||||
var fullContent: String {
|
||||
return frontmatter + content
|
||||
}
|
||||
}
|
||||
10
AddToObsidian/Resources/AddToObsidian.entitlements
Normal file
10
AddToObsidian/Resources/AddToObsidian.entitlements
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>com.apple.security.app-sandbox</key>
|
||||
<false/>
|
||||
<key>com.apple.security.files.user-selected.read-write</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"scale" : "1x",
|
||||
"size" : "16x16"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"scale" : "2x",
|
||||
"size" : "16x16"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"scale" : "1x",
|
||||
"size" : "32x32"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"scale" : "2x",
|
||||
"size" : "32x32"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"scale" : "1x",
|
||||
"size" : "128x128"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"scale" : "2x",
|
||||
"size" : "128x128"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"scale" : "1x",
|
||||
"size" : "256x256"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"scale" : "2x",
|
||||
"size" : "256x256"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"scale" : "1x",
|
||||
"size" : "512x512"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"scale" : "2x",
|
||||
"size" : "512x512"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
6
AddToObsidian/Resources/Assets.xcassets/Contents.json
Normal file
6
AddToObsidian/Resources/Assets.xcassets/Contents.json
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
20
AddToObsidian/Resources/Assets.xcassets/MenuBarIcon.imageset/Contents.json
vendored
Normal file
20
AddToObsidian/Resources/Assets.xcassets/MenuBarIcon.imageset/Contents.json
vendored
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"scale" : "2x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
},
|
||||
"properties" : {
|
||||
"preserves-vector-representation" : true,
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
||||
30
AddToObsidian/Resources/Info.plist
Normal file
30
AddToObsidian/Resources/Info.plist
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
|
||||
<key>LSUIElement</key>
|
||||
<true/>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>Copyright 2024. All rights reserved.</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string>NSApplication</string>
|
||||
</dict>
|
||||
</plist>
|
||||
90
AddToObsidian/Services/HotKeyManager.swift
Normal file
90
AddToObsidian/Services/HotKeyManager.swift
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
import Foundation
|
||||
import Carbon
|
||||
|
||||
class HotKeyManager {
|
||||
static let shared = HotKeyManager()
|
||||
|
||||
private var hotKeyRef: EventHotKeyRef?
|
||||
private var eventHandler: EventHandlerRef?
|
||||
private var callback: (() -> Void)?
|
||||
|
||||
// Key code for 'O' key
|
||||
private let keyCode: UInt32 = 0x1F
|
||||
|
||||
// Modifiers: Control + Option + Command
|
||||
private let modifiers: UInt32 = UInt32(cmdKey | optionKey | controlKey)
|
||||
|
||||
private init() {}
|
||||
|
||||
func register(callback: @escaping () -> Void) {
|
||||
self.callback = callback
|
||||
|
||||
// Unregister any existing hotkey
|
||||
unregister()
|
||||
|
||||
// Create hotkey ID
|
||||
var hotKeyID = EventHotKeyID()
|
||||
hotKeyID.signature = OSType(0x41544F42) // "ATOB" - AddToObsidian
|
||||
hotKeyID.id = 1
|
||||
|
||||
// Install event handler
|
||||
var eventType = EventTypeSpec(eventClass: OSType(kEventClassKeyboard), eventKind: UInt32(kEventHotKeyPressed))
|
||||
|
||||
let handlerResult = InstallEventHandler(
|
||||
GetApplicationEventTarget(),
|
||||
{ (_, event, userData) -> OSStatus in
|
||||
guard let userData = userData else { return OSStatus(eventNotHandledErr) }
|
||||
let manager = Unmanaged<HotKeyManager>.fromOpaque(userData).takeUnretainedValue()
|
||||
manager.handleHotKey()
|
||||
return noErr
|
||||
},
|
||||
1,
|
||||
&eventType,
|
||||
Unmanaged.passUnretained(self).toOpaque(),
|
||||
&eventHandler
|
||||
)
|
||||
|
||||
guard handlerResult == noErr else {
|
||||
print("Failed to install event handler: \(handlerResult)")
|
||||
return
|
||||
}
|
||||
|
||||
// Register the hotkey
|
||||
let registerResult = RegisterEventHotKey(
|
||||
keyCode,
|
||||
modifiers,
|
||||
hotKeyID,
|
||||
GetApplicationEventTarget(),
|
||||
0,
|
||||
&hotKeyRef
|
||||
)
|
||||
|
||||
if registerResult != noErr {
|
||||
print("Failed to register hotkey: \(registerResult)")
|
||||
} else {
|
||||
print("Hotkey registered: Control + Option + Cmd + O")
|
||||
}
|
||||
}
|
||||
|
||||
func unregister() {
|
||||
if let hotKeyRef = hotKeyRef {
|
||||
UnregisterEventHotKey(hotKeyRef)
|
||||
self.hotKeyRef = nil
|
||||
}
|
||||
|
||||
if let eventHandler = eventHandler {
|
||||
RemoveEventHandler(eventHandler)
|
||||
self.eventHandler = nil
|
||||
}
|
||||
}
|
||||
|
||||
private func handleHotKey() {
|
||||
DispatchQueue.main.async { [weak self] in
|
||||
self?.callback?()
|
||||
}
|
||||
}
|
||||
|
||||
deinit {
|
||||
unregister()
|
||||
}
|
||||
}
|
||||
45
AddToObsidian/Services/NoteFileService.swift
Normal file
45
AddToObsidian/Services/NoteFileService.swift
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import Foundation
|
||||
|
||||
enum NoteFileError: LocalizedError {
|
||||
case noVaultPath
|
||||
case writeError(Error)
|
||||
case invalidPath
|
||||
|
||||
var errorDescription: String? {
|
||||
switch self {
|
||||
case .noVaultPath:
|
||||
return "No Obsidian vault folder selected. Please select a folder in Settings."
|
||||
case .writeError(let error):
|
||||
return "Failed to save note: \(error.localizedDescription)"
|
||||
case .invalidPath:
|
||||
return "The selected folder is no longer accessible."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class NoteFileService {
|
||||
static let shared = NoteFileService()
|
||||
|
||||
private let settingsManager = SettingsManager.shared
|
||||
|
||||
private init() {}
|
||||
|
||||
func save(note: Note) throws -> URL {
|
||||
guard let vaultPath = settingsManager.obsidianVaultPath else {
|
||||
throw NoteFileError.noVaultPath
|
||||
}
|
||||
|
||||
guard settingsManager.hasValidVaultPath else {
|
||||
throw NoteFileError.invalidPath
|
||||
}
|
||||
|
||||
let fileURL = vaultPath.appendingPathComponent(note.filename)
|
||||
|
||||
do {
|
||||
try note.fullContent.write(to: fileURL, atomically: true, encoding: .utf8)
|
||||
return fileURL
|
||||
} catch {
|
||||
throw NoteFileError.writeError(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
94
AddToObsidian/Services/SettingsManager.swift
Normal file
94
AddToObsidian/Services/SettingsManager.swift
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
import Foundation
|
||||
import AppKit
|
||||
|
||||
class SettingsManager: ObservableObject {
|
||||
static let shared = SettingsManager()
|
||||
|
||||
private let obsidianVaultPathKey = "obsidianVaultPath"
|
||||
private let obsidianVaultBookmarkKey = "obsidianVaultBookmark"
|
||||
|
||||
@Published var obsidianVaultPath: URL? {
|
||||
didSet {
|
||||
if let path = obsidianVaultPath {
|
||||
UserDefaults.standard.set(path.path, forKey: obsidianVaultPathKey)
|
||||
saveSecurityScopedBookmark(for: path)
|
||||
} else {
|
||||
UserDefaults.standard.removeObject(forKey: obsidianVaultPathKey)
|
||||
UserDefaults.standard.removeObject(forKey: obsidianVaultBookmarkKey)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private init() {
|
||||
loadSavedPath()
|
||||
}
|
||||
|
||||
private func loadSavedPath() {
|
||||
// Try to restore from security-scoped bookmark first
|
||||
if let bookmarkData = UserDefaults.standard.data(forKey: obsidianVaultBookmarkKey) {
|
||||
do {
|
||||
var isStale = false
|
||||
let url = try URL(
|
||||
resolvingBookmarkData: bookmarkData,
|
||||
options: .withSecurityScope,
|
||||
relativeTo: nil,
|
||||
bookmarkDataIsStale: &isStale
|
||||
)
|
||||
|
||||
if isStale {
|
||||
// Bookmark is stale, try to create a new one
|
||||
saveSecurityScopedBookmark(for: url)
|
||||
}
|
||||
|
||||
if url.startAccessingSecurityScopedResource() {
|
||||
obsidianVaultPath = url
|
||||
return
|
||||
}
|
||||
} catch {
|
||||
print("Failed to resolve bookmark: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to plain path (may not have permissions)
|
||||
if let pathString = UserDefaults.standard.string(forKey: obsidianVaultPathKey) {
|
||||
obsidianVaultPath = URL(fileURLWithPath: pathString)
|
||||
}
|
||||
}
|
||||
|
||||
private func saveSecurityScopedBookmark(for url: URL) {
|
||||
do {
|
||||
let bookmarkData = try url.bookmarkData(
|
||||
options: .withSecurityScope,
|
||||
includingResourceValuesForKeys: nil,
|
||||
relativeTo: nil
|
||||
)
|
||||
UserDefaults.standard.set(bookmarkData, forKey: obsidianVaultBookmarkKey)
|
||||
} catch {
|
||||
print("Failed to save bookmark: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
func selectFolder(completion: @escaping (Bool) -> Void) {
|
||||
let panel = NSOpenPanel()
|
||||
panel.canChooseFiles = false
|
||||
panel.canChooseDirectories = true
|
||||
panel.allowsMultipleSelection = false
|
||||
panel.message = "Select your Obsidian vault folder"
|
||||
panel.prompt = "Select"
|
||||
|
||||
panel.begin { response in
|
||||
if response == .OK, let url = panel.url {
|
||||
self.obsidianVaultPath = url
|
||||
completion(true)
|
||||
} else {
|
||||
completion(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var hasValidVaultPath: Bool {
|
||||
guard let path = obsidianVaultPath else { return false }
|
||||
var isDirectory: ObjCBool = false
|
||||
return FileManager.default.fileExists(atPath: path.path, isDirectory: &isDirectory) && isDirectory.boolValue
|
||||
}
|
||||
}
|
||||
47
AddToObsidian/ViewModels/NoteViewModel.swift
Normal file
47
AddToObsidian/ViewModels/NoteViewModel.swift
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
class NoteViewModel: ObservableObject {
|
||||
@Published var noteContent: String = ""
|
||||
@Published var errorMessage: String?
|
||||
@Published var showError: Bool = false
|
||||
|
||||
private let fileService = NoteFileService.shared
|
||||
let settingsManager = SettingsManager.shared
|
||||
|
||||
func saveNote() -> Bool {
|
||||
let trimmedContent = noteContent.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
|
||||
guard !trimmedContent.isEmpty else {
|
||||
showErrorMessage("Cannot save an empty note.")
|
||||
return false
|
||||
}
|
||||
|
||||
let note = Note(content: trimmedContent)
|
||||
|
||||
do {
|
||||
let savedURL = try fileService.save(note: note)
|
||||
print("Note saved to: \(savedURL.path)")
|
||||
clearNote()
|
||||
return true
|
||||
} catch {
|
||||
showErrorMessage(error.localizedDescription)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func clearNote() {
|
||||
noteContent = ""
|
||||
errorMessage = nil
|
||||
showError = false
|
||||
}
|
||||
|
||||
private func showErrorMessage(_ message: String) {
|
||||
errorMessage = message
|
||||
showError = true
|
||||
}
|
||||
|
||||
var canSave: Bool {
|
||||
settingsManager.hasValidVaultPath
|
||||
}
|
||||
}
|
||||
103
AddToObsidian/Views/NoteInputView.swift
Normal file
103
AddToObsidian/Views/NoteInputView.swift
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
import SwiftUI
|
||||
import AppKit
|
||||
|
||||
struct NoteInputView: View {
|
||||
@ObservedObject var viewModel: NoteViewModel
|
||||
@FocusState private var isTextEditorFocused: Bool
|
||||
var onSave: () -> Void
|
||||
var onCancel: () -> Void
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 12) {
|
||||
HStack {
|
||||
Image(systemName: "note.text")
|
||||
.foregroundColor(.secondary)
|
||||
Text("Quick Note to Obsidian")
|
||||
.font(.headline)
|
||||
Spacer()
|
||||
|
||||
if !viewModel.canSave {
|
||||
Text("No vault selected")
|
||||
.font(.caption)
|
||||
.foregroundColor(.orange)
|
||||
}
|
||||
}
|
||||
|
||||
TextEditor(text: $viewModel.noteContent)
|
||||
.font(.body)
|
||||
.frame(minHeight: 150)
|
||||
.focused($isTextEditorFocused)
|
||||
.scrollContentBackground(.hidden)
|
||||
.background(Color(NSColor.textBackgroundColor))
|
||||
.cornerRadius(6)
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: 6)
|
||||
.stroke(Color.secondary.opacity(0.3), lineWidth: 1)
|
||||
)
|
||||
|
||||
if viewModel.showError, let error = viewModel.errorMessage {
|
||||
HStack {
|
||||
Image(systemName: "exclamationmark.triangle.fill")
|
||||
.foregroundColor(.red)
|
||||
Text(error)
|
||||
.font(.caption)
|
||||
.foregroundColor(.red)
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
|
||||
HStack {
|
||||
Button("Cancel") {
|
||||
onCancel()
|
||||
}
|
||||
.keyboardShortcut(.escape, modifiers: [])
|
||||
|
||||
Spacer()
|
||||
|
||||
Text("Cmd+Enter to save")
|
||||
.font(.caption)
|
||||
.foregroundColor(.secondary)
|
||||
|
||||
Button("Save") {
|
||||
if viewModel.saveNote() {
|
||||
onSave()
|
||||
}
|
||||
}
|
||||
.keyboardShortcut(.return, modifiers: .command)
|
||||
.disabled(!viewModel.canSave || viewModel.noteContent.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty)
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
.frame(width: 400, height: 280)
|
||||
.background(VisualEffectView(material: .hudWindow, blendingMode: .behindWindow))
|
||||
.onAppear {
|
||||
isTextEditorFocused = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct VisualEffectView: NSViewRepresentable {
|
||||
let material: NSVisualEffectView.Material
|
||||
let blendingMode: NSVisualEffectView.BlendingMode
|
||||
|
||||
func makeNSView(context: Context) -> NSVisualEffectView {
|
||||
let view = NSVisualEffectView()
|
||||
view.material = material
|
||||
view.blendingMode = blendingMode
|
||||
view.state = .active
|
||||
return view
|
||||
}
|
||||
|
||||
func updateNSView(_ nsView: NSVisualEffectView, context: Context) {
|
||||
nsView.material = material
|
||||
nsView.blendingMode = blendingMode
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
NoteInputView(
|
||||
viewModel: NoteViewModel(),
|
||||
onSave: {},
|
||||
onCancel: {}
|
||||
)
|
||||
}
|
||||
90
AddToObsidian/Views/SettingsView.swift
Normal file
90
AddToObsidian/Views/SettingsView.swift
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
import SwiftUI
|
||||
|
||||
struct SettingsView: View {
|
||||
@ObservedObject var settingsManager = SettingsManager.shared
|
||||
@State private var showingFolderPicker = false
|
||||
|
||||
var body: some View {
|
||||
Form {
|
||||
Section {
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
Text("Obsidian Vault Location")
|
||||
.font(.headline)
|
||||
|
||||
HStack {
|
||||
if let path = settingsManager.obsidianVaultPath {
|
||||
Image(systemName: "folder.fill")
|
||||
.foregroundColor(.blue)
|
||||
Text(path.path)
|
||||
.lineLimit(1)
|
||||
.truncationMode(.middle)
|
||||
} else {
|
||||
Image(systemName: "folder")
|
||||
.foregroundColor(.secondary)
|
||||
Text("No folder selected")
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
|
||||
Button("Select Folder...") {
|
||||
settingsManager.selectFolder { _ in }
|
||||
}
|
||||
}
|
||||
.padding(.vertical, 8)
|
||||
}
|
||||
|
||||
Section {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Text("Keyboard Shortcuts")
|
||||
.font(.headline)
|
||||
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
HStack {
|
||||
Text("Open note window:")
|
||||
Spacer()
|
||||
Text("Control + Option + Cmd + O")
|
||||
.font(.system(.body, design: .monospaced))
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
|
||||
HStack {
|
||||
Text("Save note:")
|
||||
Spacer()
|
||||
Text("Cmd + Enter")
|
||||
.font(.system(.body, design: .monospaced))
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
|
||||
HStack {
|
||||
Text("Cancel:")
|
||||
Spacer()
|
||||
Text("Escape")
|
||||
.font(.system(.body, design: .monospaced))
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(.vertical, 8)
|
||||
}
|
||||
|
||||
Section {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Text("About")
|
||||
.font(.headline)
|
||||
|
||||
Text("Notes are saved with YAML frontmatter containing the creation date. File names follow the format: yyyy-MM-dd_HH-mm-ss.md")
|
||||
.font(.caption)
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
.padding(.vertical, 8)
|
||||
}
|
||||
}
|
||||
.formStyle(.grouped)
|
||||
.frame(width: 450, height: 350)
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
SettingsView()
|
||||
}
|
||||
2
LICENSE
2
LICENSE
|
|
@ -1,6 +1,6 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2026 Paweł Orzech
|
||||
Copyright (c) 2024
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
|
|||
66
README.md
Normal file
66
README.md
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
# AddToObsidian
|
||||
|
||||
A lightweight macOS menu bar app for quickly adding notes to your Obsidian vault using a global keyboard shortcut.
|
||||
|
||||
## Features
|
||||
|
||||
- **Menu bar app** - Lives in your menu bar, no Dock icon
|
||||
- **Global keyboard shortcut** - Press `Control + Option + Cmd + O` from any application to open the note window
|
||||
- **Quick save** - Press `Cmd + Enter` to save your note
|
||||
- **Cancel with Escape** - Press `Escape` to close without saving
|
||||
- **YAML frontmatter** - Notes are saved with creation date metadata
|
||||
- **Automatic file naming** - Files are named with timestamp: `2024-01-19_14-30-45.md`
|
||||
|
||||
## Installation
|
||||
|
||||
1. Download `AddToObsidian-v1.0.0.zip` from the [Releases](https://github.com/yourusername/AddToObsidian/releases) page
|
||||
2. Unzip and move `AddToObsidian.app` to your Applications folder
|
||||
3. Open the app (you may need to right-click and select "Open" on first launch due to Gatekeeper)
|
||||
4. Grant Accessibility permissions when prompted (required for global keyboard shortcut)
|
||||
|
||||
## Setup
|
||||
|
||||
1. Right-click the menu bar icon and select **Settings**
|
||||
2. Click **Select Folder** and choose your Obsidian vault folder
|
||||
3. Start adding notes with `Control + Option + Cmd + O`
|
||||
|
||||
## Keyboard Shortcuts
|
||||
|
||||
| Shortcut | Action |
|
||||
|----------|--------|
|
||||
| `⌃⌥⌘O` | Open note window (global) |
|
||||
| `⌘↩` | Save note |
|
||||
| `⎋` | Cancel / Close window |
|
||||
|
||||
## Note Format
|
||||
|
||||
Notes are saved as Markdown files with YAML frontmatter:
|
||||
|
||||
```markdown
|
||||
---
|
||||
created: 2024-01-19T14:30:45Z
|
||||
---
|
||||
|
||||
Your note content here...
|
||||
```
|
||||
|
||||
## Requirements
|
||||
|
||||
- macOS 13.0 (Ventura) or later
|
||||
- Accessibility permissions (for global keyboard shortcut)
|
||||
|
||||
## Building from Source
|
||||
|
||||
1. Clone the repository
|
||||
2. Open `AddToObsidian.xcodeproj` in Xcode 15+
|
||||
3. Build and run (`Cmd + R`)
|
||||
|
||||
## Privacy
|
||||
|
||||
- No data is collected or transmitted
|
||||
- Notes are stored only in your selected Obsidian vault folder
|
||||
- The app uses security-scoped bookmarks for persistent folder access
|
||||
|
||||
## License
|
||||
|
||||
MIT License - see [LICENSE](LICENSE) for details
|
||||
Loading…
Reference in a new issue