Skip to content

Instantly share code, notes, and snippets.

@n1chre
Forked from jonschlinkert/open-iterm-from-finder.md
Last active May 26, 2022 13:23
Show Gist options
  • Save n1chre/4b3e2f29b3f03f152d4dbb34a1a659a3 to your computer and use it in GitHub Desktop.
Save n1chre/4b3e2f29b3f03f152d4dbb34a1a659a3 to your computer and use it in GitHub Desktop.
Add an icon to your finder toolbar to open iTerm2 in the current folder.
(*
Open Terminal Here
Written by Brian Schlining
source: http://hohonuuli.blogspot.hr/2016/02/iterm2-version-3-open-iterm-here-script.html
*)
property debug : false
-- 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
-- this version can handle this weirdo case: a folder named "te'st"ö te%s`t"
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
-- just open a terminal and cd to thePath
--set newWindow to (create window with default profile)
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

Open iTerm from finder

forked from https://gist.github.com/jonschlinkert/7683131911c0cfd18d5cf8e818adffbc

  1. Open Automator
  2. Create an Application
  3. Choose Actions > Utilities > Run Applescript on the left side
  4. Paste the contents of iTerm2 Here.applescript into the window.
  5. Save the application to Applications folder
  6. Go to Applications folder
  7. Press right click on iTerm2.app, click on the icon in the top left corner and hit cmd + c
  8. Press right click on iTerm2 Here.app, click on the icon in the top left corner and hit cmd + v
  9. drag the script onto the Finder window while holding the cmd key
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment