Permalink
Browse files

cdf to cd into whatever is the forefront Finder window. by the illust…

…rious @sindresorhus
  • Loading branch information...
1 parent 699f23f commit e67d1bc0319aa7f9ab224b47a59d9ec32e780c61 @paulirish committed Nov 15, 2012
Showing with 5 additions and 0 deletions.
  1. +5 −0 .functions
View
@@ -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() {

7 comments on commit e67d1bc

@mathiasbynens
Contributor

Totally stealing this.

@sindresorhus

Feel free! :D

@matijs
Contributor
matijs commented on e67d1bc Apr 16, 2013

What he said.

@jvhellemond

Still can't find my CDs...

@sindresorhus

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

Awesome! Thank you!

@leecade

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.