2012-02-27 64 views
0

我最近在我的Mac上使用Wine安裝了Warcraft3:TFT,因爲Mac版本不支持支持 Lion。我使用Applescript編寫了一個腳本來運行Wine的終端命令,然後禁用我的熱門角落,這樣我就不會在瀏覽屏幕時遇到任何問題。Applescript將作爲腳本運行但不是應用程序

我寫了腳本,它運行良好,通過Applescript(編譯>運行)。嘗試將腳本另存爲應用程序時出現真正的問題。我把它保存爲一個應用程序,然後嘗試運行應用程序(名爲「魔獸爭霸III - 冰封王座」),並得到這個錯誤:

error message on script app execution

這裏是腳本本身:

set settings1 to {"-", "Desktop", "Start Screen Saver", "Mission Control"} 
set settings2 to {"-", "-", "-", "-"} 

tell application "Terminal" 
    do script "/opt/local/bin/wine ~/.wine/drive_c/Program\\ Files/Warcraft\\ III/war3.exe" 
end tell 

tell application "System Preferences" 
    reveal pane id "com.apple.preference.expose" 
    activate 
    tell application "System Events" 
    tell window "Mission Control" of process "System Preferences" 
     click button "Hot Corners…" 
     tell sheet 1 
      tell group 1 
       set theSettings to settings2 
       set functionKeys to false 
       repeat with k from 1 to 4 
        set theValue to item k of theSettings 
        tell pop up button k 
         if value is not theValue then 
          click 
          click menu item theValue of menu 1 
         end if 
        end tell 
       end repeat 
      end tell 
      click button "OK" 
     end tell 
    end tell 
end tell 
quit 
end tell 

display alert "Done playing?" buttons {"Yes"} 
set response to button returned of the result 
if response is "Yes" then 
--Start return to normal settings 
tell application "System Preferences" 
    reveal pane id "com.apple.preference.expose" 
    activate 
    tell application "System Events" 
     tell window "Mission Control" of process "System Preferences" 
      click button "Hot Corners…" 
      tell sheet 1 
       tell group 1 
        set theSettings to settings1 
        set functionKeys to true 
        repeat with k from 1 to 4 
         set theValue to item k of theSettings 
         tell pop up button k 
          if value is not theValue then 
           click 
           click menu item theValue of menu 1 
          end if 
         end tell 
        end repeat 
       end tell 
       click button "OK" 
      end tell 
     end tell 
    end tell 
    quit 
end tell 
--End return to normal settings 

--quit X11 and terminal 
tell application "X11" 
    quit 
end tell 
tell application "Terminal" 
    quit 
end tell 
end if 

這是我第一次用Applescript寫的,所以可能會出現一些我沒有看到的錯誤。預先感謝您的任何建議或意見!

回答

1

您的錯誤代碼與您的AppleScript沒有直接關係。錯誤-10810是Launch Services錯誤代碼,表示通用即未知錯誤。當OS X的進程表結束時,它似乎經常被拋出。有一個非常徹底的background post on the issue at the X Labs,完成一步一步的指示診斷(並可能補救)的問題。

在OT註釋中,我注意到您使用GUI腳本來打開或關閉熱角。這是不必要的:獅王系統事件可以編寫腳本通過其揭露首套房,即

property hotCornerSettings : {} 

to disableHotCorners() 
    set hotCorners to {} 
    tell application "System Events" 
     tell expose preferences 
      set end of hotCorners to a reference to bottom left screen corner 
      set end of hotCorners to a reference to top left screen corner 
      set end of hotCorners to a reference to top right screen corner 
      set end of hotCorners to a reference to bottom right screen corner 
      repeat with hotCorner in hotCorners 
       set hotCornerProps to properties of hotCorner 
       set end of hotCornerSettings to {hotCorner, {activity:activity of hotCornerProps, modifiers:modifiers of hotCornerProps}} 
       set properties of hotCorner to {activity:none, modifiers:{}} 
      end repeat 
     end tell 
    end tell 
end disableHotCorners 

to restoreHotCorners() 
    tell application "System Events" 
     tell expose preferences 
      repeat with settings in hotCornerSettings 
       set properties of item 1 of settings to item 2 of settings 
      end repeat 
     end tell 
    end tell 
end restoreHotCorners 

...這備件你的蠕蟲可以在與GUI腳本這些設置。

+0

感謝您對Lion的揭露反應和信息。我對代碼有點困惑,因爲它看起來沒有任何設置存儲在任何地方。它如何知道它是否恢復正確的設置?再次,抱歉我對Applescript的無知:/ – wchristiansen 2012-02-27 21:47:47

+0

@Floofer:它將設置存儲在第一行的AppleScript屬性中。腳本運行後,屬性保持它們的值(它們只在腳本重新編譯時重新初始化)。 [Apple腳本語言指南](https://developer.apple.com/library/mac/#documentation/AppleScript/Conceptual/AppleScriptLangGuide/conceptual/ASLR_variables.html#//apple_ref/doc/uid/TP40000983-CH223-SW10 )有關於屬性和範圍的所有細節。 – kopischke 2012-02-27 21:56:24

+0

@Floofer:啊......剛剛得到你的問題(並且很抱歉添加了另一條評論,我的5分鐘編輯窗口已通過):腳本將當前設置存儲在上述屬性中 - 即未禁用時的熱角設置。這意味着您不必將這些代碼硬編碼到腳本中,並且該腳本將始終恢復到找到的狀態。 注意我只提供處理程序。您將不得不添加'do shell script'行,調用提供的兩個處理程序和quit命令(順便說一下,它可以寫成單行程,即「tell application」X11「quit」)。 – kopischke 2012-02-27 22:07:37

相關問題