Tuesday, October 27, 2020

#1 2020-10-16 08:23:44 pm

farmingmoney
Member
Registered: 2020-01-13
Posts: 9

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

Offline

 

#2 2020-10-16 10:41:58 pm

KniazidisR
Member
Registered: 2019-03-03
Posts: 1352

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

farmingmoney wrote:


I want to know why it doesn't work. and I want to know how to fix it


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.

Last edited by KniazidisR (2020-10-16 10:46:49 pm)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

#3 2020-10-17 07:08:17 am

farmingmoney
Member
Registered: 2020-01-13
Posts: 9

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

KniazidisR wrote:

1) is enabled GUI scripting on this remote Mac?


How can I do it in macOS catalina 10.15.7 ? cool

Last edited by farmingmoney (2020-10-17 07:38:46 am)

Offline

 

#4 2020-10-22 11:17:46 pm

KniazidisR
Member
Registered: 2019-03-03
Posts: 1352

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

farmingmoney wrote:

KniazidisR wrote:

1) is enabled GUI scripting on this remote Mac?


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:

Applescript:


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

Last edited by KniazidisR (2020-10-22 11:22:57 pm)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

#5 2020-10-23 02:21:31 am

Fredrik71
Member
Registered: 2019-10-23
Posts: 417

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

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.

4. On your local machine you use ssh to remote login.
5. 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.


I could teach you to cook but I couldn't do anything if you do not have desire or commitment for it.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)