Skip to content

Commit

Permalink
cdf to cd into whatever is the forefront Finder window. by the illust…
Browse files Browse the repository at this point in the history
…rious @sindresorhus
  • Loading branch information
paulirish committed Nov 15, 2012
1 parent 699f23f commit e67d1bc
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .functions
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ function f() {
find . -name "$1"
}

# cd into whatever is the forefront Finder window.
cdf() { # short for cdfinder
cd "`osascript -e 'tell app "Finder" to POSIX path of (insertion location as alias)'`"
}


# lets toss an image onto my server and pbcopy that bitch.
function scpp() {
Expand Down

7 comments on commit e67d1bc

@mathiasbynens
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally stealing this.

@sindresorhus
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free! :D

@matijs
Copy link
Contributor

@matijs matijs commented on e67d1bc Apr 16, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What he said.

@jvhellemond
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still can't find my CDs...

@sindresorhus
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here another one for you nice people:

cds() {
    osascript -e 'on run pwd
set f to posix file pwd
tell app "Finder"
if number of Finder windows is 0 then
open f
else
set target of window 1 to f
end
end
end' "$PWD" > /dev/null
}

The opposite of cdf. Will open the the current Terminal path in the existing Finder window.

open . works too, but opens a new window.

@sapegin
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Thank you!

@leecade
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks uglify, but fixed some issue :)

https://gist.github.com/leecade/2878638

function cd.() {
    if [ "`osascript -e 'tell application "System Events" to "Finder" is in (get name of processes)'`" = "true" ]; then

        if [ "`osascript -e 'tell application "Finder" to get collapsed of front window' 2>/dev/null`" != "false" ]; then

            if [ "`osascript -e 'tell application "System Events" to "TotalFinderCrashWatcher" is in (get name of processes)'`" = "true" ];then
                open .
                osascript -e 'tell application "System Events" to tell process "Finder" to keystroke "w" using {command down}' -e 'tell application "System Events" to tell process "Finder" to keystroke "h" using {command down}'
            else
                finderState=`osascript -e 'tell application "System Events" to set visible of application process "Finder" to true' -e 'tell application "Finder" to set collapsed of front window to true' 2>/dev/null`
            fi
        fi

        finder=`osascript -e 'tell application "Finder" to set curName to (POSIX path of (target of front window as alias))' 2>/dev/null`

        if [ -z "$finder" ]; then
            echo "Failed to find \"Finder\""
        else
            echo "$finder"
            cd "$finder"
        fi

    else
        echo "\"Finder\" is not running"
    fi
}

Please sign in to comment.