我最近在我的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