我最近在我的Mac上使用Wine安裝了Warcraft3:TFT,因爲Mac版本不支持支持 Lion。我使用Applescript編寫了一個腳本來運行Wine的終端命令,然後禁用我的熱門角落,這樣我就不會在瀏覽屏幕時遇到任何問題。Applescript將作爲腳本運行但不是應用程序
我寫了腳本,它運行良好,通過Applescript(編譯>運行)。嘗試將腳本另存爲應用程序時出現真正的問題。我把它保存爲一個應用程序,然後嘗試運行應用程序(名爲「魔獸爭霸III - 冰封王座」),並得到這個錯誤:
這裏是腳本本身:
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寫的,所以可能會出現一些我沒有看到的錯誤。預先感謝您的任何建議或意見!
感謝您對Lion的揭露反應和信息。我對代碼有點困惑,因爲它看起來沒有任何設置存儲在任何地方。它如何知道它是否恢復正確的設置?再次,抱歉我對Applescript的無知:/ – wchristiansen 2012-02-27 21:47:47
@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
@Floofer:啊......剛剛得到你的問題(並且很抱歉添加了另一條評論,我的5分鐘編輯窗口已通過):腳本將當前設置存儲在上述屬性中 - 即未禁用時的熱角設置。這意味着您不必將這些代碼硬編碼到腳本中,並且該腳本將始終恢復到找到的狀態。 注意我只提供處理程序。您將不得不添加'do shell script'行,調用提供的兩個處理程序和quit命令(順便說一下,它可以寫成單行程,即「tell application」X11「quit」)。 – kopischke 2012-02-27 22:07:37