2

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.

Script:

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

Example:

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
david$ 
2
  • Is there a question left to answer?
    – Daniel Beck
    Nov 6, 2010 at 16:24
  • As it turns out it's not actually working. Nov 7, 2010 at 3:31

2 Answers 2

1

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.

1
  • I couldn't get it to work in the open window, but it helped me to my eventual solution so thanks! Nov 5, 2010 at 0:10
0

I changed the script to

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

and created a bash script

#!/bin/bash
cd "`osascript ~/Scripts/cdf.scpt`"

and created a bash alias

cdf='. ~/Scripts/cdf.sh'

You must log in to answer this question.

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