Skip to content

Instantly share code, notes, and snippets.

@ptone
Created August 12, 2012 20:03
Show Gist options
  • Save ptone/3334103 to your computer and use it in GitHub Desktop.
Save ptone/3334103 to your computer and use it in GitHub Desktop.
cd to current finder window
# cdf: cd to the directory in the Finder's front window
alias cdf='cd "$(~/UNIX/bin/posd)"'
#!/bin/sh
thePath="$( osascript<<END
try
tell application "Finder" to set the source_folder to (folder of the front window) as alias
on error -- no open folder windows
set the source_folder to path to desktop folder as alias
end try
set thePath to (POSIX path of the source_folder as string)
set result to thePath
END
)"
#thePath="$( echo "$thePath" | /usr/bin/sed 's/ /\\ /g' )"
if [ -n "${thePath%/*}" ]; then
if [ -d "$thePath" ]; then
echo "${thePath%/}"
else
echo "${thePath%/*}"
fi
else
echo "/"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment