ATLief
ATLief

Reputation: 437

My applescript can't close for some reason?

This is the applescript I have, it's for opening Minecraft and auto-logging in. It works fine when it's not bundled in an application. Whenever I bundle it however, at the end it stays open, then gives me the error "End of [Script] doesn't understand end of script". What am I doing wrong?

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

Upvotes: 2

Views: 480

Answers (2)

r_benjamin
r_benjamin

Reputation: 53

Try this:

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

Upvotes: 0

regulus6633
regulus6633

Reputation: 19032

Remove the lines containing "end run". Normally when you run an applescript it executes the code in the "on run" handler composed like this...

on run
   -- your code goes here
end run

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

However, if you omit the on run handler applescript assumes that everything is in an on run handler. So you don't really need it unless there's other specific applescript handlers you want to use like "on quit".

Never though would you use "end run" without an "on run" statement, and never would you use "end run" multiple times.

Upvotes: 1

Related Questions