Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

hehe299792458

macrumors 6502a
Original poster
Dec 13, 2008
783
3
I'm trying to run these two scripts in one file in AppleScript:

Code:
global UserName
global ServerName
global passwd

on ActivateX11()
    tell application "Terminal"
        activate
    end tell
end ActivateX11

on ActivateTerminal()
    set ScriptCommand to "ssh -X -N -D 8080 " & UserName & "@" & ServerName
    tell application "Terminal"
        activate
        do script ScriptCommand --  Establish the SSH connection
        delay 3 -- Wait 3 seconds for the password prompt to appear
        do script passwd in window 1
    end tell
end ActivateTerminal

on run
    set ServerName to "xxx" --  The name of the server to connect to
    set UserName to "yyy" --  The user to connect as
    set passwd to "zzz" --  The password for the user
    ActivateX11()
    ActivateTerminal()
end run


tell application "Finder"
    activate
end tell

tell application "System Events"
    if UI elements enabled then
        click menu item "SSH" of menu "Location" of menu item "Location" of menu "Apple" of menu bar 1 of process "Finder"
    else
        tell application "System Preferences"
            activate
            set current pane to pane "com.apple.preference.universalaccess"
            display dialog "UI element scripting is not enabled. Check \"Enable access for assistive devices\""
        end tell
    end if
end tell



But I get the following error message:

Code:
The run handler is specified more than once, or there were top-level commands in addition to the run handler.


What can I do to fix this?
 
as far as I can tell, the previous run handlers were closed before the second script. I thought those should prevent these errors from occuring

Yep, you're right. The run handlers are closed. It's the second part of the error message you need to be looking at:

Code:
...or there were top-level commands in addition to the run handler

I expect that all the stuff after the "end run" line probably belongs one of your handlers. Or perhaps in a handler of its own, depending on how you expect your script to behave.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.