How to login a remote Mac using AppleScript?

320 Views Asked by At

What I need to achieve is this, using AppleScript:

  1. Wake a remote iMac
  2. Input password
  3. Accept password to login

What I succeeded to do so far was enabling Remote Events and connecting to the iMac but now I’m stuck. Here is what I tried so far:

set remotemachine to "eppc://192.168.0.26"

tell application "System Events" of machine remotemachine
    keystroke 123
end tell

However, this leads me nowhere. It says to me something like "Error: App is not launched. number -600". Sorry, it’s not the exact English string.

Does anyone knows what I’m doing wrong?

Thanks in advance.

1

There are 1 best solutions below

1
vadian On

Two major problems:

  1. System Events doesn't run permanently on the remote machine and you cannot launch applications from the local machine. You have to launch System Events with the Finder which is the only application which runs permanently.

  2. You have to address the Finder and System Events of the remote machine explicitly but add also a using terms from block because the terminology must be resolved locally.

This example launches System Events on the remote machine and retuns the path to desktop folder

set RemoteMachine to "eppc://192.168.0.26"

tell application "Finder" of machine RemoteMachine
    using terms from application "Finder"
        if "System Events" is not in (get name of processes) then
            open application file id "com.apple.systemevents"
            repeat until "System Events" is in (get name of every process)
                delay 1
            end repeat
        end if
    end using terms from
end tell

tell application "System Events" of machine RemoteMachine
    using terms from application "System Events"
        set x to path of desktop folder
    end using terms from
end tell