gingerbeardman / stapler

My take on the classic Macintosh app Stapler (with a little bit of LaunchList)
https://blog.gingerbeardman.com/2024/08/10/stapler-i-remade-a-32-year-old-classic-macintosh-app/
MIT License
215 stars 7 forks source link

Does stapler use absolute path for files? #18

Closed wwzhang closed 4 weeks ago

wwzhang commented 4 weeks ago

I tried this in synced folders on different computers, I found it can't open stapler file created on another computer with difference in absolute path of folders between the two computers. Could it possible use relative path to the .stapled file for documents in it?

gingerbeardman commented 4 weeks ago

Stapler uses security scoped bookmarks, which are provided by macOS and are the modern version of an "alias". They have many benefits over symlink or a simple plain text path, but some downsides as you have discovered.

A bookmark stores the relative and absolute paths, inode numbers, volume name, and much more information. This allows the shortcut to be resolved even if the file is moved on the disk, or even to another volume on the same filesystem (you could say "computer").

I simply ask the system for a bookmark, and store it. Then I ask the system to open the file at the bookmark and it does it. It's a pretty hands-off approach.

So, I think the request for bookmarks to work across computers is something only Apple can address.

But, perhaps there's a way I can add an option to repoint an alias to a file if it really can't be found. I'll give it some thought.


I used an app called Precize to prepare this example, more info on that and bookmarks here

Example bookmark (base64 encoded)

Ym9va+QCAAAAAAQQMAAAAI8vbWmG+UY2OTc3//Pg3XU6WQToJK9lghBuu76aLcn24AEAAAQAAAADAwAAABgAKAUAAAABAQAAVXNlcnMAAAAEAAAAAQEAAG1hdHQJAAAAAQEAAERvd25sb2FkcwAAAAoAAAABAQAAMjAyNC0wOC0wOQAACwAAAAEBAABzdGFwbGVyLnBuZwAUAAAAAQYAABAAAAAgAAAALAAAAEAAAABUAAAACAAAAAQDAAAWZgAAAAAAAAgAAAAEAwAAlOcEAAAAAAAIAAAABAMAAItlBwAAAAAACAAAAAQDAACuC0QJAAAAAAgAAAAEAwAAKIJECQAAAAAUAAAAAQYAAIQAAACUAAAApAAAALQAAADEAAAACAAAAAAEAABBxjNLe0ad8RgAAAABAgAAAQAAAAAAAAAPAAAAAAAAAAAAAAAAAAAACAAAAAQDAAADAAAAAAAAAAQAAAADAwAA9QEAAAgAAAABCQAAZmlsZTovLy8MAAAAAQEAAE1hY2ludG9zaCBIRAgAAAAEAwAAAJCClucAAAAIAAAAAAQAAEHGL8gGgAAAJAAAAAEBAABBMjY0MEQ4Mi0wNDI5LTQ4RUMtODU1Mi1CMjA1MjdENjgxNDcYAAAAAQIAAIEAAAABAAAA7xMAAAEAAAAAAAAAAAAAAAEAAAABAQAALwAAAAAAAAABBQAAzAAAAP7///8BAAAAAAAAABAAAAAEEAAAaAAAAAAAAAAFEAAA1AAAAAAAAAAQEAAAAAEAAAAAAABAEAAA8AAAAAAAAAACIAAAzAEAAAAAAAAFIAAAPAEAAAAAAAAQIAAATAEAAAAAAAARIAAAgAEAAAAAAAASIAAAYAEAAAAAAAATIAAAcAEAAAAAAAAgIAAArAEAAAAAAAAwIAAA2AEAAAAAAAABwAAAIAEAAAAAAAARwAAAIAAAAAAAAAASwAAAMAEAAAAAAAAQ0AAABAAAAAAAAAA=

Contained information (decoded)

Optional([__C.NSURLResourceKey(_rawValue: NSURLBookmarkAllPropertiesKey): {
    NSURLBookmarkOriginalRelativePathComponentsArrayKey =     (
        Users,
        matt,
        Downloads,
        "2024-08-09",
        "stapler.png"
    );
    NSURLBookmarkOriginalRelativePathKey = "Users/matt/Downloads/2024-08-09/stapler.png";
    NSURLBookmarkOriginalVolumeNameKey = "Macintosh HD";
    NSURLCreationDateKey = "2024-08-09 18:27:02 +0000";
    NSURLIsDirectoryKey = 0;
    NSURLIsRegularFileKey = 1;
    NSURLIsSymbolicLinkKey = 0;
    NSURLIsVolumeKey = 0;
    NSURLNameKey = "stapler.png";
    NSURLVolumeCreationDateKey = "2024-08-04 10:31:41 +0000";
    NSURLVolumeIsAutomountedKey = 0;
    NSURLVolumeIsBrowsableKey = 1;
    NSURLVolumeIsEjectableKey = 0;
    NSURLVolumeIsInternalKey = 1;
    NSURLVolumeIsLocalKey = 1;
    NSURLVolumeIsReadOnlyKey = 0;
    NSURLVolumeIsRemovableKey = 0;
    NSURLVolumeNameKey = "Macintosh HD";
    NSURLVolumeSupportsPersistentIDsKey = 1;
    NSURLVolumeTotalCapacityKey = 994662584320;
    NSURLVolumeURLKey = "file:///";
    NSURLVolumeUUIDStringKey = "A2640D82-0429-48EC-8552-B20527D68147";
    "_NSURLBookmarkIsRevocableKey" = 0;
    "_NSURLBookmarkSecurityScopeCryptoKeyKey" = {length = 32, bytes = 0x8f2f6d69 86f94636 393737ff f3e0dd75 ... 106ebbbe 9a2dc9f6 };
    "_NSURLBookmarkURLStringKey" = "file:///Users/matt/Downloads/2024-08-09/stapler.png";
    "_NSURLFileIDKey" = 155484712;
    "_NSURLPathKey" = "/Users/matt/Downloads/2024-08-09/stapler.png";
    "_NSURLVolumeIsDiskImageKey" = 0;
    "_NSURLVolumeIsiPodKey" = 0;
}])