-
-
Save andre3k1/e63570022db777bea002 to your computer and use it in GitHub Desktop.
Open iTerm2 tab from Finder here
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
##### | |
## Open iTerm2 tab from Finder | |
## | |
## 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 | |
## | |
## Usage Instructions: | |
## 1) Open Automator | |
## 2) Create a new Service document | |
## 3) Change "Service receives selected" to "Files or folders" in "Finder" | |
## 4) Search for "Run AppleScript" in the left sidebar | |
## 5) paste in the following script, and hit <cmd-s> to save | |
#### | |
on run {input, parameters} | |
tell application "Finder" | |
set my_file to first item of input | |
set filetype to (kind of (info for my_file)) | |
-- Treats OS X applications as files. To treat them as folders, integrate this SO answer: | |
-- http://stackoverflow.com/a/6881524/640517 | |
if filetype is "Folder" or filetype is "Volume" 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 | |
try | |
set t to the last terminal | |
on error | |
set t to (make new terminal) | |
end try | |
tell t | |
launch session "Default Session" | |
tell the last session | |
write text "cd " & theDir | |
write text "ls" | |
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