有时候需要关闭工程再打开工程。手动操作很简单。
但利用AppleScript可以更方便些~
Xcode打开的工程有两种 workspace和project
脚本里优先处理workspace,如果没有workspace可以处理,就处理project
cocoapods的模版建立的工程有Example文件夹,所以加入了Example文件夹的处理>>>
更新和cocoapods命令行一起用 github.com/dacaiguoguo…
#!/bin/zsh
export LANG=en_US.UTF-8
deal_path="${1}"
if [ -d "${1}/Example" ];
then
deal_path="${1}/Example"
fi
#处理workspace文件 用 AppleScript 的 close doc 关闭已经打开的
for file in `ls $deal_path | grep 'xcworkspace'`
do
echo $file
ascript=$(echo "tell application \"Xcode\"
set docs to (document of every window)
repeat with doc in docs
if class of doc is workspace document then
set docPath to path of doc
log docPath
if docPath begins with \"${1}\" then
log docPath
close doc
return
end if
end if
end repeat
end tell")
# echo $ascript
# 执行AppleScript脚本
osascript -e $ascript
open -a Xcode $deal_path/$file
exit 0
done
#处理xcodeproj文件
for file in `ls $deal_path| grep 'xcodeproj'`
do
echo $file
open -a Xcode $deal_path/$file
exit 0
done