Created
February 26, 2011 19:38
-
-
Save DocOnDev/845541 to your computer and use it in GitHub Desktop.
Open iTerm Here
This file contains 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
(* | |
iTerm Here - Michael "Doc" Norton | |
Version 0.1.1 | |
A Button for opening the iTerm.app and CD-ing to the location of the selected files or folder. | |
Inspired by the workflow from Jeroen Leenars, but using iTerm instead of Terminal. | |
Additional contributions to concept (and code) from: | |
Felipe Meneguzzi | |
See http://fmeneguzzi.blogspot.com/2009/09/open-iterm-here.html for more information. | |
Marc Liyanage | |
See http://putnamhill.net/applescript/open-iterm-here for more information. | |
*) | |
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 open_item(this_folder) | |
end tell | |
end run | |
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 open_item(this_item) | |
end repeat | |
end open | |
on open_item(this_path) | |
set thePath to (quoted form of POSIX path of this_path) | |
set iTermRunning to isAppRunning("iTerm") | |
tell application "iTerm" | |
if iTermRunning then | |
set myTerm to (make new terminal) | |
tell myTerm to launch session "Default Session" | |
else | |
activate | |
set myTerm to first terminal | |
tell myTerm to activate current session | |
end if | |
tell myTerm | |
tell the last session | |
write text "cd " & thePath & "; clear" | |
end tell | |
end tell | |
end tell | |
end open_item | |
on isAppRunning(app_name) | |
tell application "System Events" to set app_list to every application process whose name is app_name | |
if the (count of app_list) > 0 then | |
return true | |
else | |
return false | |
end if | |
end isAppRunning |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can change the first part to make it work in search folders such as Lion's "All My Files" :