Skip to content

Instantly share code, notes, and snippets.

@darwin
Last active August 31, 2022 21:59
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save darwin/262db85585ea563f3060edb467dd2c95 to your computer and use it in GitHub Desktop.
Save darwin/262db85585ea563f3060edb467dd2c95 to your computer and use it in GitHub Desktop.
This is a simple automation script to open a new Finder window with a pre-defined set of paths each in a new tab. Run it in `/Applications/Utilities/Script Editor.app` (hint: you can save the script as a standalone executable from there).
set paths to {"/Users/darwin/Music", "/Users/darwin/Desktop"}
-- initialize new Finder window
tell application "Finder"
activate
set finderWindow to make new Finder window
set toolbar visible of finderWindow to true
end tell
-- open all paths as new tabs
repeat with path in paths
set applePath to POSIX file path
tell application "System Events"
keystroke "t" using command down
end tell
tell application "Finder"
set target of finderWindow to applePath
end tell
end repeat
-- close the initial tab
tell application "Finder"
activate
tell application "System Events"
keystroke tab using control down
keystroke "w" using command down
end tell
end tell
@darwin
Copy link
Author

darwin commented Feb 3, 2020

@B1zguy
Copy link

B1zguy commented Jul 1, 2021

Can confirm script works when replacing 'open all paths as new tabs' section with darwin's link.
Tested on MacOS Catalina (10.15.6 19G73).

Thank you!

@ecrarity
Copy link

ecrarity commented Aug 31, 2022

When running the line:

set target of finderWindow to applePath

The error

Script Error
Finder got an error: AppleEvent handler failed.

occurs.

I have tried my best to search this behavior, but I am still coming up short. Can you please assist? It would be much appreciated.

OS | Monterey 12.5.1
Script Editor 2.11 (227) (AppleScript 2.8)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment