2

这是我拥有的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
4

2 回答 2

1

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

on run
   -- your code goes here
end run

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

但是,如果您省略 on run 处理程序,applescript 会假定所有内容都在 on run 处理程序中。因此,除非您想使用其他特定的 applescript 处理程序,例如“退出时”,否则您实际上并不需要它。

你永远不会在没有“on run”语句的情况下使用“end run”,也永远不会多次使用“end run”。

于 2013-01-30T16:34:04.973 回答
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
于 2014-02-20T16:59:51.113 回答