简体   繁体   中英

Applescript will run as script but not application

I recently installed Warcraft3:TFT on my Mac using Wine because the Mac version doen't support Lion. I wrote a script using Applescript to run the terminal command for Wine and then disable my hot corners so I wouldn't have any issues with navigating the screen.

I wrote the script and it runs fine through Applescript (Compile > Run). The real problem comes in when trying save the script as an application. I save it as an application and then try to run the application (named "Warcraft III - The Frozen Throne") and get this error:

执行脚本应用程序时出现错误消息

Here is the script itself:

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

This is the first time I have actually written in Applescript so there maybe some sort of error in it that I am not seeing. Thanks in advance for any advice or input!

Your error code has nothing to do directly with your AppleScript. Error –10810 is a Launch Services error code signaling a generic, ie unknown error. It seems to get thrown quite often when OS X' process table runs over. There is a quite thorough background post on the issue at the X Labs , complete with step by step instructions to diagnose (and possibly remedy) the issue.

On an OT note, I notice you use GUI scripting to toggle Hot Corners on or off. This is unnecessary: Lion's System Events can script these settings via its Expose Preferences Suite , ie

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

… which spares you the can of worms that is GUI scripting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM