Skip to content

Instantly share code, notes, and snippets.

@leecade
Created June 5, 2012 22:51
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save leecade/2878638 to your computer and use it in GitHub Desktop.
Save leecade/2878638 to your computer and use it in GitHub Desktop.
bash:cd_finder_path
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
}
@leecade
Copy link
Author

leecade commented Jun 5, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment