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 ""
		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

  1. Make GUI Script on your remote computer.
  2. Use osascript on your remote computer
  3. Include !#/usr/bin/osascript in the first line of your script and run chmod +x scriptname

Now the script could be run and take args if that is a option in your script.

  1. On your local machine you use ssh to remote login.
  2. You could build a simple bash script to do this and run the above osascript.

If you understand you correctly you like to directly use GUI scripting on the remote computer.

You have to solve every step before you could do everything.

In this forum you could get lot of information about GUI scripting.
On the internet you could find information about how to make osascripts as bash script.
And you could also get information how the command ssh works.