bookmark-cli: OS X bookmark data for scripters
I’ve been working on a simple solution for backing up and restoring OS X tags after catastrophes. Ultimately this is going to have to be more than a script, but I have most of the pieces in place. As part of the experiment I wanted to be able to handle files being renamed and moved. That’s best handled by the file bookmarking portions of the Cocoa API, so I wrote a little CLI to capture and restore bookmark data for a file or folder.
It’s very rudimentary, but it doesn’t need to do much more than it already does. You pass a file path to the save
command and it returns a base64-encoded string that you can store however you like. Pass that string back to the find
command and it will tell you where the file is, even if it’s been renamed or moved.
$ BOOKMARK=$(bookmark save filename.ext)
$ mv filename.ext filename-2.ext
$ bookmark find $BOOKMARK
=> filename-2.ext
This is really handy on your local filesystem. Unfortunately, it doesn’t do diddly squat if you move the file to an external drive, network drive, or send it through certain sync services. I have those cases mostly covered in my tag backup tool, which I’ll post when it’s ready. This little tool was built as a handy helper and not something for a script to rely entirely upon.
The source is on GitHub if you want to compile it yourself. The download below is a binary that should be usable on any 10.8+ Mac. Let me know if you have issues.
bookmark-cli v1
CLI for storing Cocoa bookmark data for a file from scripts and the command line
Published 07/05/14.
Updated 07/05/14. Changelog