Skip to content

Instantly share code, notes, and snippets.

@prashanta
Created July 4, 2010 22:29
Show Gist options
  • Save prashanta/463813 to your computer and use it in GitHub Desktop.
Save prashanta/463813 to your computer and use it in GitHub Desktop.
Switching between Terminal and Finder
set a to item 1 of getFrontApp()
if a contains "Finder" then
tell application "Finder"
set the_folder to (folder of the front window) as text
set the_folder to POSIX path of the_folder
set the_folder to (do shell script "echo " & the_folder & " | sed 's/ /\\\\ /g'")
end tell
tell application "Terminal"
do script "cd " & the_folder & ";clear;pwd"
activate
end tell
else if a contains "Terminal" then
tell application "Terminal"
do script "open ." in window 1
end tell
end if
-- -----------------------
on getFrontApp()
tell application "System Events" to set frontwin to name of every process whose frontmost is true and visible ≠ false
return frontwin
end getFrontApp
-- -----------------------
on getCurrentFolder()
tell application "Finder"
set theFolder to (path to desktop folder as alias)
repeat with i from 0 to (count of windows)
try
get folder of window i
set theFolder to result
exit repeat
end try
end repeat
return theFolder as alias
end tell
end getCurrentFolder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment