Trying to silence Terminal Applescript

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$ 

David Kanarek

Posted 2010-11-04T21:34:09.090

Reputation: 165

Is there a question left to answer? – Daniel Beck – 2010-11-06T16:24:22.797

As it turns out it's not actually working. – David Kanarek – 2010-11-07T03:31:43.827

Answers

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'

David Kanarek

Posted 2010-11-04T21:34:09.090

Reputation: 165

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.

JRobert

Posted 2010-11-04T21:34:09.090

Reputation: 6 128

I couldn't get it to work in the open window, but it helped me to my eventual solution so thanks! – David Kanarek – 2010-11-05T00:10:51.470