Skip to content

Instantly share code, notes, and snippets.

@gwerbin
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gwerbin/27edc1c4531a6b95ef1b to your computer and use it in GitHub Desktop.
Save gwerbin/27edc1c4531a6b95ef1b to your computer and use it in GitHub Desktop.
In Automator, create a new Workflow, add action Run Applescript, and replace the contents of the text box with this entire file. At the top, where it says "Service receives selected ___ in ___" select "Files or Folders" in the first drop-down menu, and "Finder.app" in the second. You can set a keyboard shortcut in System Preferences -> Keyboard …
on run {input, parameters}
tell application "Finder"
set currentSelection to selection
set currentFolder to target of front Finder window as text
end tell
tell application "iTerm" -- this should work if you replace "iTerm" with "Terminal" (untested)
if currentSelection = {} then
set thePath to POSIX path of currentFolder
set targetType to "folder"
else
set theTarget to item 1 of currentSelection as alias
set thePath to POSIX path of theTarget
set targetType to kind of (info for (theTarget) without size)
end if
make new terminal
tell the current terminal
activate current session
launch session "Default Session"
tell the last session
if targetType is "folder" then
write text "cd " & quoted form of thePath
else
write text "cd " & quote & "$(dirname " & quoted form of thePath & ")" & quote
end if
write text "clear && pwd"
end tell
end tell
end tell
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment