Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an Applescript that changes directory for the front Terminal window to the front Finder window. It works fine, but it also outputs text which clutters my terminal window.

Does anyone have any idea how to make it shut up? I'm pretty terrible at Applescript so any advice/improvements would be appreciated.


tell application "Finder"
    set thePath to (quoted form of POSIX path of (target of front window as alias))
    tell application "Terminal"
            do script "cd " & thePath in front window
    end tell
on error error_message
end try
end tell


david$ cdf
cd '/Users/david/'        <---Make this go away
tab 1 of window id 2810   <---This too
david$ cd '/Users/david/' <---Doubt anything can be done about this
share|improve this question
Is there a question left to answer? – Daniel Beck Nov 6 '10 at 16:24
As it turns out it's not actually working. – David Kanarek Nov 7 '10 at 3:31
Please post your solution as an answer, and accept that? – Arjan Nov 7 '10 at 22:17

If you're willing to try another script, Open Terminal Here opens a terminal session in the directory you're viewing. If you already have a session open, it'll cd that session to the directory you're viewing. You can put it on your Finder tool bar to keep it handy. Plus, a simple one-line change in the obvious place in the script will make it pushd instead, so it's easy to get your session back to where you came from. I use it a lot.

share|improve this answer
I couldn't get it to work in the open window, but it helped me to my eventual solution so thanks! – David Kanarek Nov 5 '10 at 0:10
up vote 0 down vote accepted

I changed the script to

tell application "Finder"
    return (POSIX path of (target of front window as alias))
on error error_message
end try
end tell

and created a bash script

cd "`osascript ~/Scripts/cdf.scpt`"

and created a bash alias

cdf='. ~/Scripts/'
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .