Created
June 5, 2012 22:51
-
-
Save leecade/2878638 to your computer and use it in GitHub Desktop.
bash:cd_finder_path
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function cd.() { | |
# 检查 Finder 是否执行 | |
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 | |
# 隐藏TotalFinder(最小化(commond+m)报错) | |
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 | |
# 最小化Finder(隐藏状态(commond+h) 报错) | |
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ref: http://www.jsser.com/t/75