I'm trying to run these two scripts in one file in AppleScript:
But I get the following error message:
What can I do to fix this?
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?