Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos 我的applescript可以';你为什么不关门?_Macos_Applescript - Fatal编程技术网

Macos 我的applescript可以';你为什么不关门?

Macos 我的applescript可以';你为什么不关门?,macos,applescript,Macos,Applescript,这是我的applescript,用于打开Minecraft和自动登录。当它没有捆绑在应用程序中时,它可以正常工作。然而,每当我捆绑它时,它都会在最后保持打开状态,然后给出错误“end of[Script]不理解脚本的结尾”。我做错了什么 if application "Minecraft" is running then beep 1 display dialog "Error: Minecraft cannot be launched as it is already runn

这是我的applescript,用于打开Minecraft和自动登录。当它没有捆绑在应用程序中时,它可以正常工作。然而,每当我捆绑它时,它都会在最后保持打开状态,然后给出错误“end of[Script]不理解脚本的结尾”。我做错了什么

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

删除包含“结束运行”的行。通常,当您运行applescript时,它会执行“运行时”处理程序中的代码,如下所示

on run
   -- your code goes here
end run

-- any handlers go here like your doWithTimeout() handler
但是,如果省略运行时处理程序,applescript将假定所有内容都在运行时处理程序中。因此,除非您想使用其他特定的applescript处理程序,如“on quit”,否则您并不真正需要它

但是,如果没有“on run”语句,您决不会使用“end run”,也决不会多次使用“end run”。

尝试以下方法:

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