Is it possible to use the ‘keystroke’ command on the remote server?

Trying to type in a Google spreadsheet on a remote server using the keystroke command.
Is it possible to use the ‘keystroke’ command on the remote server?
If I enter the keystroke command like the code below, number -1728 is returned.
If I delete the code at line number 8, this script works fine
I want to know why it doesn’t work. and I want to know how to fix it
Both the client and the server Mac have the same MacOS version as 10.15.7.

1 property remoteMachine : “eppc://tom:1234@iMac.local”
2 with timeout of 30 seconds
3 using terms from application “Finder”
4 tell application “Google Chrome” of machine remoteMachine
5 activate
6 tell application “System Events” of machine remoteMachine
7 tell process “Google Chrome”
8 keystroke “hello world!” <———— attention
9 say (the clipboard)
10 end tell
11 end tell
12 end tell
13 end using terms from
14 end timeout

Your remote server as I understand is also Mac computer. But 1) is enabled GUI scripting on this remote Mac? 2) You activate Google Chrome on the remote Mac, but you should check if window 1 of application process “Google Chrome” appeared on the screen already (that is, exists), only then you can keystroke.

KniazidisR wrote:

How can I do it in macOS catalina 10.15.7 ? :cool:

To be the System Events of remote machine able to do GUI scripting, it should be added, and checkbox should be checked here:


tell application "System Preferences"
	tell pane id "com.apple.preference.security"
		reveal anchor "Privacy_Accessibility"
	end tell
end tell

So, you should give to System Events of your remote computer permissions to control your remote computer