Simulating Keystrokes through terminal

I am learning/messing around with ssh, and was wondering how I could remotely simulate keystrokes through terminal. I have looked through the internet and have found things that don't work, such as tell application "System Events" to keystroke "k" but none of the things seem to work. Thanks!

MacBook Air

Posted on May 14, 2017 6:29 PM

Reply
8 replies

May 15, 2017 6:44 PM in response to bpel12

You need to understand what ssh is for. It lets you use the unix command line from a remote computer. You just type the letter "k". "k" appears on the screen. No, you cannot send the "k" to the macos gui.


What have you done so far?


You need to learn shell commands. the default shell is bash.


If you want to see macos gui screen, you need to run a remote desktop. How you setup a remote desktop depends on your environment. ssh doesn't support the macos gui.


You need to learn how to use the terminal.


Unix Navigation Commands

May 15, 2017 5:48 AM in response to bpel12

With ssh, a lot depends on what you want to do on the other end.


You can do things like:

ssh username@remote.system.address command_or_shell_script arg1 arg2 arg3 ...

and run many things on the remote system.


You could pipe commands into the ssh stdin


(echo command arg1 arg2 arg3 ...

echo script arg1 arg2 arg3 ...

echo another_cmd args...

etc...

) ssh username@remote.system.address


You can use the 'expect' commnd to script input to the remote system where expect and adapt to responses from the other side (see "man expect"; and then do lots of Googling for example)


Now if what you want to do is have ssh send remote screen interactions, such as mouse movements, or changing screen focus, or in anyway interacting with the GUI of the remote system, that is going to be more difficult, as often times the remote ssh session is NOT running in the same environment as the GUI and when you issue system event, apple script, automator actions via an ssh session they often do not have an open channel into the GUI.


So your mileage may vary.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Simulating Keystrokes through terminal

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.