我不确定我做错了但是在这个命令完成之后,脚本结束了还有另一个命令要完成,有人知道我做错了什么。感谢
我输入它,它贯穿
tell application "Finder"
activate
display dialog "Are you sure you want to shut down your computer now?" buttons {"Restart", "Sleep", "Shutdown"} with icon alias ((path to me as text) & "Contents:Resources:power.icns")
if the button returned of the result is "Restart" then
set theSeconds to 10
repeat theSeconds times
display dialog theSeconds buttons {"Stop"} giving up after 1 with title "Restarting..." with icon 0 default button 1
set theSeconds to (theSeconds - 1)
set volume 6
beep 1
end repeat
tell application "Finder"
restart
end tell
else
if the button returned of the result is "Sleep" then
set theSeconds to 10
repeat theSeconds times
display dialog theSeconds buttons {"Stop"} giving up after 1 with title "Sleeping..." with icon 0 default button 1
set theSeconds to (theSeconds - 1)
set volume 6
beep 1
end repeat
tell application "Finder"
sleep
end tell
else
if the button returned of the result is "Shutdown" then
set theSeconds to 10
repeat theSeconds times
display dialog theSeconds buttons {"Stop"} giving up after 1 with title "Shutting Down..." with icon 0 default button 1
set theSeconds to (theSeconds - 1)
set volume 6
beep 1
end repeat
tell application "Finder"
shut down
end tell
这是之后的命令,但不会运行
set appLocation to path to me as string
set theFile to appLocation & "Contents:Resources:iPanic.app"
tell application "Finder" to open file theFile
delay 8
tell application "Terminal"
activate
set currentTab to do script {"defaults write com.apple.LaunchServices LSQuarantine -bool YES"}
delay 1
do script {"Killall Finder"} in currentTab
end tell
答案 0 :(得分:0)
脚本运行结束的原因是,当脚本到达该点时,您的计算机已重新启动,正在休眠或已关闭。
restart,sleep或shutdown命令必须是脚本中的最后一个命令。
您可以将脚本的最后一部分放入子例程,并在重启,睡眠或关闭命令之前调用该子例程。
将脚本的最后部分包裹起来:
on finalPart()
…
end finalPart
然后你像这样调用那个子程序:
finalPart() of me
restart
当然,您可以将子程序命名为比“finalPart”更具描述性的内容。
此外,在调用restart,sleep和shutdown命令的地方,您不需要周围的tell块,因为您此时已经在与Finder交谈。您可以在重启,睡眠和关机命令的正上方和正下方删除该行。
在这里:
tell application "Terminal"
activate
set currentTab to do script {"defaults write com.apple.LaunchServices LSQuarantine -bool YES"}
delay 1
do script {"Killall Finder"} in currentTab
end tell
您不必使用终端应用程序运行shell脚本。 “do shell script”命令是适用于每个应用程序的标准添加。要退出Finder,您所要做的就是告诉它退出。因此,除非您在“Killall Finder”脚本中有更多内容而不是仅仅退出Finder,否则您可以像这样编写以上内容:
tell application "Finder"
do shell script "defaults write com.apple.LaunchServices LSQuarantine -bool YES"
delay 1
quit
end tell
当然,如果脚本的那部分已经在Finder tell块中,你可以从上面删除tell命令。