Created
May 23, 2023 11:19
-
-
Save stephancasas/1650f84d225e28ac9802758b0e2b99f9 to your computer and use it in GitHub Desktop.
AppleScript: Open last Finder location
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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