Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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$ 
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
add comment

2 Answers

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
add comment
up vote 0 down vote accepted

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'
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.