macOS Bookmarks


(Christopher Stone) #1

Hey Folks,

People who are interested in the structure of macOS aliases and bookmarks may find these articles illuminating.

And Howard’s Precize.app and alisma command line tool may be of use to some.

My question to you all is:

Do we have any AppleScriptObjC code that will resolve a base64 bookmark reference like Howard’s tools?

-Chris


(Shane Stanley) #2

It looks like he’s using an undocumented resource key, NSURLBookmarkAllPropertiesKey.

So assuming you have a Base-64 string of the bookmark (and I’m not at all sure where he’s getting that from), it’s just a matter of:

use scripting additions
use framework "Foundation"

set theString to "XYZ..." -- Base-64 string
set theData to current application's NSData's alloc()'s initWithBase64EncodedString:theString options:(current application's NSDataBase64DecodingIgnoreUnknownCharacters)
set theResult to current application's |NSURL|'s resourceValuesForKeys:{"NSURLBookmarkAllPropertiesKey"} fromBookmarkData:theData
theResult as record -- if you want a record instead of a dictionary

If you want to get it directly from a file, you can use:

use scripting additions
use framework "Foundation"

set posixPath to POSIX path of (choose file)
set anNSURL to current application's |NSURL|'s fileURLWithPath:posixPath
set theData to current application's |NSURL|'s bookmarkDataWithContentsOfURL:anNSURL |error|:(missing value)
set theResult to current application's |NSURL|'s resourceValuesForKeys:{"NSURLBookmarkAllPropertiesKey"} fromBookmarkData:theData
theResult as record -- if you want a record instead of a dictionary

It’s entirely possible that NSURLBookmarkAllPropertiesKey is dependent on OS version and/or disk format.