2014-09-28 71 views
-1

我不知道我在做什么错误,但在此命令完成后,脚本结束还有另一个命令来完成,谁会知道我做错了什么。由于脚本结束后,即使仍然有更多的命令

我在进入这个,它贯穿

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 

回答

1

您的脚本的末尾没有按”的原因t运行是在脚本到达该点时,计算机已重新启动,正在休眠或已关闭。

重启,休眠或关机命令需要是脚本中最后一个命令。

您可以将脚本的最后部分变为子例程,并在重新启动,睡眠或关闭命令之前调用该子例程。

包装你的脚本是这样的最后一部分:

on finalPart() 
… 
end finalPart 

然后你调用子程序这样的:

finalPart() of me 
restart 

可以命名不是“finalPart子程序更多的东西描述给你“ 当然。

此外,如果您正在调用重新启动,睡眠和关闭命令,则不需要位于其周围的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脚本”命令是一个标准加法,适用于每个应用程序。为了退出Finder,你所要做的就是告诉它退出。所以,除非你已经在你的“Killall发现者”脚本不仅仅是退出查找更多事情,你也许可以写上这样的:

tell application "Finder" 
    do shell script "defaults write com.apple.LaunchServices LSQuarantine -bool YES" 
    delay 1 
    quit 
end tell 

当然,如果脚本的一部分已经是一个Finder中告诉块,你可以从上面删除tell命令。

+0

感谢你告诉我所有这些:)我仍然在学习苹果脚本,我的脚本有点混乱,但是这有助于。我只是想知道我的 'finalpart() restart' 做我需要做的代码,每个按钮(休眠,重启,关机)即可。因此,对于睡眠命令,我将把子程序放在最后的'finalpart(),sleep'中,并且我必须复制并粘贴每个命令的子程序 – 2014-09-29 03:20:05

相关问题