.:. gotblogua .:.

November 19, 2007
@ 5:42 / 5:42 am
cat(s) :: techy
by :: gotjoshua

Open in Terminal Applescript

Automator Screen Shot Open in Terminal
i recently posted over at the osxhints forums with a script that i hacked together to enable right- clicking on a folder in OS X and choosing “Open in Terminal” from the Automator menu.

Its pretty handy to be able to use the Finder to navigate instead of cd .. etc etc… and then to start a terminal session just where you want to be. Of course it can also added to with another do script statement to reuse an inactive terminal window to do any other script… and i also noticed that if you put a \n into the command string it will do a line break and create a sequence of commands (but it breaks if you hit the hammer button to compile the script - you have to save it without compiling if you want to do this little /n newline trick).

here is the script for reference:
on run {input, parameters}
repeat with i in input
set theWin to (quoted form of POSIX path of (i as alias))
end repeat
--set myWin to window 1
--set theWin to (quoted form of POSIX path of (target of myWin as alias))
set commandString to "cd " & theWin --& " ls -al"
------------------
tell application "System Events"
if not (exists process "Terminal") then
tell application "Terminal"
activate --start terminal if needed
end tell
end if
repeat while not (exists process "Terminal")
delay 1 --wait for terminal to be ready
end repeat
end tell --Sys Events
----------------
tell application "Terminal" -- Get a free window to run
activate
set windowCount to (count of the windows)
if windowCount is greater than 0 then
repeat with w from 1 to windowCount
if window 1 is busy then
set frontmost of window 1 to false
else
do script commandString in window 1
set frontmost of window 1 to true
return
end if
end repeat
end if
tell window 1
do script commandString
set frontmost to true
end tell
end tell
end run

note:the formatting looks nicer on the forum

No Comments »

No comments yet.

Leave a comment

You must be logged in to post a comment.

RSS feed for comments on this post. TrackBack URI

this wordPress site is: Earth friendly web hosting powered by wind and solar energy