Skip to content

Instantly share code, notes, and snippets.

@nuno-azevedo
Last active May 9, 2019 14:37
Show Gist options
  • Save nuno-azevedo/4d4d07acbcd87600372f4399809df04e to your computer and use it in GitHub Desktop.
Save nuno-azevedo/4d4d07acbcd87600372f4399809df04e to your computer and use it in GitHub Desktop.
Open iTerm2 from Finder
-- When the toolbar script icon is clicked
on run
tell application "Finder"
try
set this_folder to (the target of the front window) as alias
on error
set this_folder to startup disk
end try
my process_item(this_folder)
end tell
end run
-- This handler processes folders dropped onto the toolbar script icon
on open these_items
repeat with i from 1 to the count of these_items
set this_item to item i of these_items
my process_item(this_item)
end repeat
end open
-- This subroutine processes does the actual work
on process_item(this_item)
set thePath to quoted form of POSIX path of this_item
set theCmd to " cd " & thePath & "; clear;"
tell application "iTerm"
activate
set aWindow to current window
if aWindow is equal to missing value then
set aWindow to (create window with default profile)
else
tell aWindow
set t to (create tab with default profile)
end tell
end if
tell current session of aWindow
write text " cd " & thePath & "; clear;"
end tell
end tell
end process_item
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment