├── .gitignore ├── Makefile ├── README.md ├── bookmark.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcuserdata │ └── ttscoff.xcuserdatad │ └── xcschemes │ └── xcschememanagement.plist └── bookmark ├── bookmark-Prefix.pch ├── bookmark.1 └── main.m /.gitignore: -------------------------------------------------------------------------------- 1 | Build 2 | # Created by https://www.toptal.com/developers/gitignore/api/objective-c 3 | # Edit at https://www.toptal.com/developers/gitignore?templates=objective-c 4 | 5 | ### Objective-C ### 6 | # Xcode 7 | # 8 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 9 | 10 | ## User settings 11 | xcuserdata/ 12 | 13 | ## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) 14 | *.xcscmblueprint 15 | *.xccheckout 16 | 17 | ## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) 18 | build/ 19 | DerivedData/ 20 | *.moved-aside 21 | *.pbxuser 22 | !default.pbxuser 23 | *.mode1v3 24 | !default.mode1v3 25 | *.mode2v3 26 | !default.mode2v3 27 | *.perspectivev3 28 | !default.perspectivev3 29 | 30 | ## Obj-C/Swift specific 31 | *.hmap 32 | 33 | ## App packaging 34 | *.ipa 35 | *.dSYM.zip 36 | *.dSYM 37 | 38 | # CocoaPods 39 | # We recommend against adding the Pods directory to your .gitignore. However 40 | # you should judge for yourself, the pros and cons are mentioned at: 41 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 42 | # Pods/ 43 | # Add this line if you want to avoid checking in source code from the Xcode workspace 44 | # *.xcworkspace 45 | 46 | # Carthage 47 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 48 | # Carthage/Checkouts 49 | 50 | Carthage/Build/ 51 | 52 | # fastlane 53 | # It is recommended to not store the screenshots in the git repo. 54 | # Instead, use fastlane to re-generate the screenshots whenever they are needed. 55 | # For more information about the recommended setup visit: 56 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 57 | 58 | fastlane/report.xml 59 | fastlane/Preview.html 60 | fastlane/screenshots/**/*.png 61 | fastlane/test_output 62 | 63 | # Code Injection 64 | # After new code Injection tools there's a generated folder /iOSInjectionProject 65 | # https://github.com/johnno1962/injectionforxcode 66 | 67 | iOSInjectionProject/ 68 | 69 | ### Objective-C Patch ### 70 | 71 | # End of https://www.toptal.com/developers/gitignore/api/objective-c 72 | 73 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for building and installing an Xcode project 2 | 3 | # Variables 4 | PROJECT_NAME = bookmark 5 | TARGET = bookmark 6 | BUILD_DIR = Build/Release 7 | 8 | # Determine Homebrew prefix 9 | ifeq ($(HOMEBREW_PREFIX),) 10 | ifeq ($(shell command -v brew),) 11 | HOME_BREW_PREFIX := /usr/local 12 | else 13 | HOME_BREW_PREFIX := $(shell brew --prefix) 14 | endif 15 | else 16 | HOME_BREW_PREFIX := $(HOMEBREW_PREFIX) 17 | endif 18 | 19 | INSTALL_DIR = $(HOME_BREW_PREFIX)/bin 20 | 21 | # Default target 22 | all: build install 23 | 24 | # Build the project using xcodebuild 25 | build: 26 | xcodebuild -project $(PROJECT_NAME).xcodeproj -target $(TARGET) -configuration Release 27 | 28 | # Install the built binary 29 | install: 30 | cp $(BUILD_DIR)/$(TARGET) $(INSTALL_DIR)/ 31 | 32 | # Clean build artifacts 33 | clean: 34 | xcodebuild -project $(PROJECT_NAME).xcodeproj -target $(TARGET) clean 35 | 36 | .PHONY: all build install clean -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # bookmark-cli 2 | 3 | This is an extremely simple tool for use in shell scripting. It allows you to convert a filename into bookmark data using the Cocoa APIs, returning a base64-encoded string that you can store. You can then locate the referenced file using that string, even if it's been renamed or moved. 4 | 5 | ## Installation 6 | 7 | Installation requires Xcode. Before running the commands below, make sure Xcode is selected for command line use with `sudo xcode-select -s /Applications/Xcode.app`. 8 | 9 | 1. Clone the repo with 10 | 2. Go to the cloned directory 11 | 3. Run make 12 | 13 | ``` 14 | git clone https://github.com/ttscoff/bookmark-cli.git 15 | cd bookmark-cli 16 | make 17 | ``` 18 | 19 | ## Usage: 20 | 21 | example: 22 | 23 | $ BOOKMARK=$(bookmark save filename.ext) 24 | $ mv filename.ext filename.bak 25 | $ bookmark find "$BOOKMARK" 26 | 27 | In a script, capture the response of `bookmark save ...` and save it instead of a filename in an object and be able to restore it no matter where it goes. Within reason, of course. -------------------------------------------------------------------------------- /bookmark.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 932013B51968B1D800862871 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 932013B41968B1D800862871 /* Foundation.framework */; }; 11 | 932013B81968B1D800862871 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 932013B71968B1D800862871 /* main.m */; }; 12 | 932013BC1968B1D800862871 /* bookmark.1 in CopyFiles */ = {isa = PBXBuildFile; fileRef = 932013BB1968B1D800862871 /* bookmark.1 */; }; 13 | /* End PBXBuildFile section */ 14 | 15 | /* Begin PBXCopyFilesBuildPhase section */ 16 | 932013AF1968B1D800862871 /* CopyFiles */ = { 17 | isa = PBXCopyFilesBuildPhase; 18 | buildActionMask = 2147483647; 19 | dstPath = /usr/share/man/man1/; 20 | dstSubfolderSpec = 0; 21 | files = ( 22 | 932013BC1968B1D800862871 /* bookmark.1 in CopyFiles */, 23 | ); 24 | runOnlyForDeploymentPostprocessing = 1; 25 | }; 26 | /* End PBXCopyFilesBuildPhase section */ 27 | 28 | /* Begin PBXFileReference section */ 29 | 932013B11968B1D800862871 /* bookmark */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = bookmark; sourceTree = BUILT_PRODUCTS_DIR; }; 30 | 932013B41968B1D800862871 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 31 | 932013B71968B1D800862871 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 32 | 932013BA1968B1D800862871 /* bookmark-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "bookmark-Prefix.pch"; sourceTree = ""; }; 33 | 932013BB1968B1D800862871 /* bookmark.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = bookmark.1; sourceTree = ""; }; 34 | /* End PBXFileReference section */ 35 | 36 | /* Begin PBXFrameworksBuildPhase section */ 37 | 932013AE1968B1D800862871 /* Frameworks */ = { 38 | isa = PBXFrameworksBuildPhase; 39 | buildActionMask = 2147483647; 40 | files = ( 41 | 932013B51968B1D800862871 /* Foundation.framework in Frameworks */, 42 | ); 43 | runOnlyForDeploymentPostprocessing = 0; 44 | }; 45 | /* End PBXFrameworksBuildPhase section */ 46 | 47 | /* Begin PBXGroup section */ 48 | 932013A81968B1D800862871 = { 49 | isa = PBXGroup; 50 | children = ( 51 | 932013B61968B1D800862871 /* bookmark */, 52 | 932013B31968B1D800862871 /* Frameworks */, 53 | 932013B21968B1D800862871 /* Products */, 54 | ); 55 | sourceTree = ""; 56 | }; 57 | 932013B21968B1D800862871 /* Products */ = { 58 | isa = PBXGroup; 59 | children = ( 60 | 932013B11968B1D800862871 /* bookmark */, 61 | ); 62 | name = Products; 63 | sourceTree = ""; 64 | }; 65 | 932013B31968B1D800862871 /* Frameworks */ = { 66 | isa = PBXGroup; 67 | children = ( 68 | 932013B41968B1D800862871 /* Foundation.framework */, 69 | ); 70 | name = Frameworks; 71 | sourceTree = ""; 72 | }; 73 | 932013B61968B1D800862871 /* bookmark */ = { 74 | isa = PBXGroup; 75 | children = ( 76 | 932013B71968B1D800862871 /* main.m */, 77 | 932013BB1968B1D800862871 /* bookmark.1 */, 78 | 932013B91968B1D800862871 /* Supporting Files */, 79 | ); 80 | path = bookmark; 81 | sourceTree = ""; 82 | }; 83 | 932013B91968B1D800862871 /* Supporting Files */ = { 84 | isa = PBXGroup; 85 | children = ( 86 | 932013BA1968B1D800862871 /* bookmark-Prefix.pch */, 87 | ); 88 | name = "Supporting Files"; 89 | sourceTree = ""; 90 | }; 91 | /* End PBXGroup section */ 92 | 93 | /* Begin PBXNativeTarget section */ 94 | 932013B01968B1D800862871 /* bookmark */ = { 95 | isa = PBXNativeTarget; 96 | buildConfigurationList = 932013BF1968B1D800862871 /* Build configuration list for PBXNativeTarget "bookmark" */; 97 | buildPhases = ( 98 | 932013AD1968B1D800862871 /* Sources */, 99 | 932013AE1968B1D800862871 /* Frameworks */, 100 | 932013AF1968B1D800862871 /* CopyFiles */, 101 | ); 102 | buildRules = ( 103 | ); 104 | dependencies = ( 105 | ); 106 | name = bookmark; 107 | productName = bookmark; 108 | productReference = 932013B11968B1D800862871 /* bookmark */; 109 | productType = "com.apple.product-type.tool"; 110 | }; 111 | /* End PBXNativeTarget section */ 112 | 113 | /* Begin PBXProject section */ 114 | 932013A91968B1D800862871 /* Project object */ = { 115 | isa = PBXProject; 116 | attributes = { 117 | LastUpgradeCheck = 0510; 118 | ORGANIZATIONNAME = "Brett Terpstra"; 119 | }; 120 | buildConfigurationList = 932013AC1968B1D800862871 /* Build configuration list for PBXProject "bookmark" */; 121 | compatibilityVersion = "Xcode 3.2"; 122 | developmentRegion = English; 123 | hasScannedForEncodings = 0; 124 | knownRegions = ( 125 | English, 126 | en, 127 | ); 128 | mainGroup = 932013A81968B1D800862871; 129 | productRefGroup = 932013B21968B1D800862871 /* Products */; 130 | projectDirPath = ""; 131 | projectRoot = ""; 132 | targets = ( 133 | 932013B01968B1D800862871 /* bookmark */, 134 | ); 135 | }; 136 | /* End PBXProject section */ 137 | 138 | /* Begin PBXSourcesBuildPhase section */ 139 | 932013AD1968B1D800862871 /* Sources */ = { 140 | isa = PBXSourcesBuildPhase; 141 | buildActionMask = 2147483647; 142 | files = ( 143 | 932013B81968B1D800862871 /* main.m in Sources */, 144 | ); 145 | runOnlyForDeploymentPostprocessing = 0; 146 | }; 147 | /* End PBXSourcesBuildPhase section */ 148 | 149 | /* Begin XCBuildConfiguration section */ 150 | 932013BD1968B1D800862871 /* Debug */ = { 151 | isa = XCBuildConfiguration; 152 | buildSettings = { 153 | ALWAYS_SEARCH_USER_PATHS = NO; 154 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 155 | CLANG_CXX_LIBRARY = "libc++"; 156 | CLANG_ENABLE_MODULES = YES; 157 | CLANG_ENABLE_OBJC_ARC = YES; 158 | CLANG_WARN_BOOL_CONVERSION = YES; 159 | CLANG_WARN_CONSTANT_CONVERSION = YES; 160 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 161 | CLANG_WARN_EMPTY_BODY = YES; 162 | CLANG_WARN_ENUM_CONVERSION = YES; 163 | CLANG_WARN_INT_CONVERSION = YES; 164 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 165 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 166 | COPY_PHASE_STRIP = NO; 167 | GCC_C_LANGUAGE_STANDARD = gnu99; 168 | GCC_DYNAMIC_NO_PIC = NO; 169 | GCC_ENABLE_OBJC_EXCEPTIONS = YES; 170 | GCC_OPTIMIZATION_LEVEL = 0; 171 | GCC_PREPROCESSOR_DEFINITIONS = ( 172 | "DEBUG=1", 173 | "$(inherited)", 174 | ); 175 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 176 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 177 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 178 | GCC_WARN_UNDECLARED_SELECTOR = YES; 179 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 180 | GCC_WARN_UNUSED_FUNCTION = YES; 181 | GCC_WARN_UNUSED_VARIABLE = YES; 182 | MACOSX_DEPLOYMENT_TARGET = 10.9; 183 | ONLY_ACTIVE_ARCH = YES; 184 | SDKROOT = macosx; 185 | }; 186 | name = Debug; 187 | }; 188 | 932013BE1968B1D800862871 /* Release */ = { 189 | isa = XCBuildConfiguration; 190 | buildSettings = { 191 | ALWAYS_SEARCH_USER_PATHS = NO; 192 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 193 | CLANG_CXX_LIBRARY = "libc++"; 194 | CLANG_ENABLE_MODULES = YES; 195 | CLANG_ENABLE_OBJC_ARC = YES; 196 | CLANG_WARN_BOOL_CONVERSION = YES; 197 | CLANG_WARN_CONSTANT_CONVERSION = YES; 198 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 199 | CLANG_WARN_EMPTY_BODY = YES; 200 | CLANG_WARN_ENUM_CONVERSION = YES; 201 | CLANG_WARN_INT_CONVERSION = YES; 202 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 203 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 204 | COPY_PHASE_STRIP = YES; 205 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 206 | ENABLE_NS_ASSERTIONS = NO; 207 | GCC_C_LANGUAGE_STANDARD = gnu99; 208 | GCC_ENABLE_OBJC_EXCEPTIONS = YES; 209 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 210 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 211 | GCC_WARN_UNDECLARED_SELECTOR = YES; 212 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 213 | GCC_WARN_UNUSED_FUNCTION = YES; 214 | GCC_WARN_UNUSED_VARIABLE = YES; 215 | MACOSX_DEPLOYMENT_TARGET = 10.9; 216 | SDKROOT = macosx; 217 | }; 218 | name = Release; 219 | }; 220 | 932013C01968B1D800862871 /* Debug */ = { 221 | isa = XCBuildConfiguration; 222 | buildSettings = { 223 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 224 | GCC_PREFIX_HEADER = "bookmark/bookmark-Prefix.pch"; 225 | MACOSX_DEPLOYMENT_TARGET = 11.5; 226 | PRODUCT_NAME = "$(TARGET_NAME)"; 227 | SDKROOT = macosx15.2; 228 | }; 229 | name = Debug; 230 | }; 231 | 932013C11968B1D800862871 /* Release */ = { 232 | isa = XCBuildConfiguration; 233 | buildSettings = { 234 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 235 | GCC_PREFIX_HEADER = "bookmark/bookmark-Prefix.pch"; 236 | MACOSX_DEPLOYMENT_TARGET = 11.5; 237 | PRODUCT_NAME = "$(TARGET_NAME)"; 238 | SDKROOT = macosx15.2; 239 | }; 240 | name = Release; 241 | }; 242 | /* End XCBuildConfiguration section */ 243 | 244 | /* Begin XCConfigurationList section */ 245 | 932013AC1968B1D800862871 /* Build configuration list for PBXProject "bookmark" */ = { 246 | isa = XCConfigurationList; 247 | buildConfigurations = ( 248 | 932013BD1968B1D800862871 /* Debug */, 249 | 932013BE1968B1D800862871 /* Release */, 250 | ); 251 | defaultConfigurationIsVisible = 0; 252 | defaultConfigurationName = Release; 253 | }; 254 | 932013BF1968B1D800862871 /* Build configuration list for PBXNativeTarget "bookmark" */ = { 255 | isa = XCConfigurationList; 256 | buildConfigurations = ( 257 | 932013C01968B1D800862871 /* Debug */, 258 | 932013C11968B1D800862871 /* Release */, 259 | ); 260 | defaultConfigurationIsVisible = 0; 261 | defaultConfigurationName = Release; 262 | }; 263 | /* End XCConfigurationList section */ 264 | }; 265 | rootObject = 932013A91968B1D800862871 /* Project object */; 266 | } 267 | -------------------------------------------------------------------------------- /bookmark.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /bookmark.xcodeproj/xcuserdata/ttscoff.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | bookmark.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /bookmark/bookmark-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header 3 | // 4 | // The contents of this file are implicitly included at the beginning of every source file. 5 | // 6 | 7 | #ifdef __OBJC__ 8 | #import 9 | #endif 10 | -------------------------------------------------------------------------------- /bookmark/bookmark.1: -------------------------------------------------------------------------------- 1 | .\"Modified from man(1) of FreeBSD, the NetBSD mdoc.template, and mdoc.samples. 2 | .\"See Also: 3 | .\"man mdoc.samples for a complete listing of options 4 | .\"man mdoc for the short list of editing options 5 | .\"/usr/share/misc/mdoc.template 6 | .Dd 7/5/14 \" DATE 7 | .Dt bookmark 1 \" Program name and manual section number 8 | .Os Darwin 9 | .Sh NAME \" Section Header - required - don't modify 10 | .Nm bookmark, 11 | .\" The following lines are read in generating the apropos(man -k) database. Use only key 12 | .\" words here as the database is built based on the words here and in the .ND line. 13 | .Nm Other_name_for_same_program(), 14 | .Nm Yet another name for the same program. 15 | .\" Use .Nm macro to designate other names for the documented program. 16 | .Nd This line parsed for whatis database. 17 | .Sh SYNOPSIS \" Section Header - required - don't modify 18 | .Nm 19 | .Op Fl abcd \" [-abcd] 20 | .Op Fl a Ar path \" [-a path] 21 | .Op Ar file \" [file] 22 | .Op Ar \" [file ...] 23 | .Ar arg0 \" Underlined argument - use .Ar anywhere to underline 24 | arg2 ... \" Arguments 25 | .Sh DESCRIPTION \" Section Header - required - don't modify 26 | Use the .Nm macro to refer to your program throughout the man page like such: 27 | .Nm 28 | Underlining is accomplished with the .Ar macro like this: 29 | .Ar underlined text . 30 | .Pp \" Inserts a space 31 | A list of items with descriptions: 32 | .Bl -tag -width -indent \" Begins a tagged list 33 | .It item a \" Each item preceded by .It macro 34 | Description of item a 35 | .It item b 36 | Description of item b 37 | .El \" Ends the list 38 | .Pp 39 | A list of flags and their descriptions: 40 | .Bl -tag -width -indent \" Differs from above in tag removed 41 | .It Fl a \"-a flag as a list item 42 | Description of -a flag 43 | .It Fl b 44 | Description of -b flag 45 | .El \" Ends the list 46 | .Pp 47 | .\" .Sh ENVIRONMENT \" May not be needed 48 | .\" .Bl -tag -width "ENV_VAR_1" -indent \" ENV_VAR_1 is width of the string ENV_VAR_1 49 | .\" .It Ev ENV_VAR_1 50 | .\" Description of ENV_VAR_1 51 | .\" .It Ev ENV_VAR_2 52 | .\" Description of ENV_VAR_2 53 | .\" .El 54 | .Sh FILES \" File used or created by the topic of the man page 55 | .Bl -tag -width "/Users/joeuser/Library/really_long_file_name" -compact 56 | .It Pa /usr/share/file_name 57 | FILE_1 description 58 | .It Pa /Users/joeuser/Library/really_long_file_name 59 | FILE_2 description 60 | .El \" Ends the list 61 | .\" .Sh DIAGNOSTICS \" May not be needed 62 | .\" .Bl -diag 63 | .\" .It Diagnostic Tag 64 | .\" Diagnostic informtion here. 65 | .\" .It Diagnostic Tag 66 | .\" Diagnostic informtion here. 67 | .\" .El 68 | .Sh SEE ALSO 69 | .\" List links in ascending order by section, alphabetically within a section. 70 | .\" Please do not reference files that do not exist without filing a bug report 71 | .Xr a 1 , 72 | .Xr b 1 , 73 | .Xr c 1 , 74 | .Xr a 2 , 75 | .Xr b 2 , 76 | .Xr a 3 , 77 | .Xr b 3 78 | .\" .Sh BUGS \" Document known, unremedied bugs 79 | .\" .Sh HISTORY \" Document history if command behaves in a unique manner -------------------------------------------------------------------------------- /bookmark/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // bookmark 4 | // 5 | // Created by Brett Terpstra on 7/5/14. 6 | // Copyright (c) 2014 Brett Terpstra. All rights reserved. 7 | // 8 | // Stupid little CLI tool to return a base64 string of encoded bookmark data 9 | // for a file 10 | // or retrieve a file when given a base64 string. 11 | 12 | #import 13 | 14 | int main(int argc, const char *argv[]) { 15 | if (argc != 3) { 16 | fprintf(stderr, "Invalid number of arguments\n"); 17 | fprintf(stderr, "Get bookmark for file: %s save filename\n" 18 | "Find file with bookmark: %s find (bookmark data)\n", 19 | argv[0], argv[0]); 20 | return 1; 21 | } 22 | @autoreleasepool { 23 | 24 | NSString *type = 25 | [NSString stringWithCString:argv[1] encoding:NSUTF8StringEncoding]; 26 | 27 | if ([type isEqual:@"save"] || [type isEqual:@"s"]) { 28 | NSString *filename = 29 | [NSString stringWithCString:argv[2] encoding:NSUTF8StringEncoding]; 30 | NSFileManager *fm = [NSFileManager defaultManager]; 31 | BOOL isDir; 32 | 33 | if ([fm fileExistsAtPath:[filename stringByExpandingTildeInPath] 34 | isDirectory:&isDir]) { 35 | NSURL *fileurl = 36 | [NSURL fileURLWithPath:[filename stringByExpandingTildeInPath]]; 37 | NSData *bookmark = [fileurl 38 | bookmarkDataWithOptions:NSURLBookmarkCreationMinimalBookmark 39 | includingResourceValuesForKeys:NULL 40 | relativeToURL:NULL 41 | error:NULL]; 42 | 43 | printf("%s", 44 | [[bookmark 45 | base64EncodedStringWithOptions: 46 | NSDataBase64EncodingEndLineWithLineFeed] UTF8String]); 47 | 48 | } else { 49 | fprintf(stderr, "File not found\n"); 50 | return 1; 51 | } 52 | 53 | } else if ([type isEqual:@"find"] || [type isEqual:@"f"]) { 54 | NSString *stringData = 55 | [NSString stringWithCString:argv[2] encoding:NSUTF8StringEncoding]; 56 | NSData *data = [[NSData alloc] 57 | initWithBase64EncodedString:stringData 58 | options: 59 | NSDataBase64DecodingIgnoreUnknownCharacters]; 60 | NSError *err; 61 | BOOL isStale; 62 | NSURL *target = 63 | [NSURL URLByResolvingBookmarkData:data 64 | options:NSURLBookmarkResolutionWithoutUI 65 | relativeToURL:NULL 66 | bookmarkDataIsStale:&isStale 67 | error:&err]; 68 | 69 | if (!err) { 70 | printf("%s", [[target path] UTF8String]); 71 | 72 | } else { 73 | return 1; 74 | } 75 | } else { 76 | fprintf(stderr, "Invalid argument\n"); 77 | fprintf(stderr, "Get bookmark for file: bookmark save filename\n" 78 | "Find file with bookmark: bookmark find (bookmark data)\n"); 79 | return 1; 80 | } 81 | } 82 | return 0; 83 | } 84 | --------------------------------------------------------------------------------