2012-02-27 65 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

相关问题