我的苹果因某种原因无法关闭?

时间:2013-01-30 15:27:55

标签: macos applescript

这是我拥有的AppleScript,它用于打开Minecraft并自动登录。当它没有捆绑在应用程序中时,它可以正常工作。无论何时我捆绑它,但最后它保持打开状态,然后给我错误“[脚本]结束不理解脚本结束”。我做错了什么?

if application "Minecraft" is running then
    beep 1
    display dialog "Error: Minecraft cannot be launched as it is already running." buttons {"Cancel"} default button 1
end if
tell application "Minecraft"
    launch
    activate
end tell
set timeoutSeconds to 1
set uiScript to "click Ul Element \"Login\" of window \"Minecraft Launcher\" of application process \"Minecraft\""
my doWithnmeout(uiScript, tlmeoutSeconds)
end run
on doWithnmeout(uiScript, tlmeoutSeconds)
    set endDate to (current date) + timeoutSeconds
    repeat
        try
            run script " tell application \"System Events\"
" & uiScript & "
end tell"
            exit repeat
        end try
    end repeat
end doWithnmeout
end run
tell application "Minecraft"
    activate
end tell
end run

2 个答案:

答案 0 :(得分:1)

删除包含“end run”的行。通常,当你运行一个applescript时,它会执行像这样组成的“on run”处理程序中的代码......

on run
   -- your code goes here
end run

-- any handlers go here like your doWithTimeout() handler

但是,如果省略运行处理程序,则applescript假定所有内容都在运行中处理程序中。所以你真的不需要它,除非你想要使用其他特定的AppleScript处理程序,比如“退出”。

永远不会在没有“运行”声明的情况下使用“结束运行”,并且绝不会多次使用“结束运行”。

答案 1 :(得分:0)

试试这个:

if application "Minecraft" is running then
    beep 1
    display dialog "Error: Minecraft cannot be launched as it is already running." buttons {"Cancel"} default button 1
end if
tell application "Minecraft"
    launch
    activate
end tell
set timeoutSeconds to 1
set uiScript to "click Ul Element \"Login\" of window \"Minecraft Launcher\" of application process \"Minecraft\""
my doWithnmeout(uiScript, tlmeoutSeconds)
end run
on doWithnmeout(uiScript, tlmeoutSeconds)
    set endDate to (current date) + timeoutSeconds
    repeat
        try
            run script " tell application \"System Events\"
" & uiScript & "
end tell"
            exit repeat
        end try
    end repeat
end doWithnmeout
end run
tell application "Minecraft"
    activate
end tell
end run
end