Skip to content

Instantly share code, notes, and snippets.

@duraki
Last active January 11, 2025 04:09
Show Gist options
  • Save duraki/9a14120e74ab7e678a99eb9621ef108f to your computer and use it in GitHub Desktop.
Save duraki/9a14120e74ab7e678a99eb9621ef108f to your computer and use it in GitHub Desktop.
An AppleScript for Automator.app to open selected item in new Finder window
# AppleScript for macOS Sonoma that opens a new Finder window/tab showing the directory of
# a selected item (file or folder). If no item is selected, the script does nothing. Can be
# used in a Shortcut.app, as a Service in the menubar item, or as a Quick Action extension.
#
# Author: H. Duraki <[email protected]>
# <https://github.com/duraki>
# Jan 11, 2025
tell application "Finder"
-- Check if there is a selection of Item/Folder
set selectedItems to selection
if selectedItems is not {} then
-- Get the folder of the first selected item
set selectedItem to item 1 of selectedItems
set parentFolder to container of selectedItem as alias
-- Open a new Finder window/tab with the item's directory
make new Finder window
set target of front window to parentFolder
-- Optionally highlight the item in the new window
select selectedItem
else
-- If no item is selected, ~do~ nothing ~or~
-- use 'display dialog ... buttons {...}' to show the dialog selection
end if
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment