Skip to content

Instantly share code, notes, and snippets.

@stephancasas
Created May 23, 2023 11:19
Show Gist options
  • Save stephancasas/1650f84d225e28ac9802758b0e2b99f9 to your computer and use it in GitHub Desktop.
Save stephancasas/1650f84d225e28ac9802758b0e2b99f9 to your computer and use it in GitHub Desktop.
AppleScript: Open last Finder location
#!/usr/bin/env osascript -l JavaScript
const App = Application.currentApplication();
App.includeStandardAdditions = true;
function run(_) {
const finderPrefs = $.NSMutableDictionary.dictionaryWithContentsOfFile(
`${$.NSHomeDirectory().js}/Library/Preferences/com.apple.finder.plist`,
);
const bookmark = finderPrefs.valueAtIndexInPropertyWithKey(
0,
'FXRecentFolders',
);
const bookmarkURL =
$.NSURL.URLByResolvingBookmarkDataOptionsRelativeToURLBookmarkDataIsStaleError(
bookmark.valueForKey('file-bookmark'),
$.NSURLBookmarkResolutionWithoutUI,
$(),
$(),
$(),
);
App.doShellScript(`open -a Finder '${bookmarkURL.path.js}'`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment