Created
February 5, 2017 19:43
-
-
Save ulasozguler/c01c0f0729aa7ff99d171e72d5163a47 to your computer and use it in GitHub Desktop.
Open in iTerm action for Finder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Adapted from these sources: | |
-- http://peterdowns.com/posts/open-iterm-finder-service.html | |
-- https://gist.github.com/cowboy/905546 | |
-- | |
-- Modified to work with files as well, cd-ing to their container folder | |
on run {input, parameters} | |
tell application "Finder" | |
set my_file to first item of input | |
set is_folder to (do shell script "file -b " & quoted form of (POSIX path of my_file)) | |
if is_folder ends with "directory" then | |
set dir_path to quoted form of (POSIX path of my_file) | |
else | |
set dir_path to quoted form of (POSIX path of (container of my_file as string)) | |
end if | |
end tell | |
CD_to(dir_path) | |
end run | |
on CD_to(theDir) | |
tell application "iTerm" | |
activate | |
set go_dir to "cd " & theDir | |
try | |
set newWindow to current window | |
on error | |
set newWindow to (create window with default profile) | |
end try | |
tell newWindow | |
tell current session of (create tab with default profile) | |
write text go_dir | |
end tell | |
end tell | |
end tell | |
end CD_to |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment