2014-09-28 70 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

相關問題