12

Is there a way for Terminal to simulate pressing multiple keys at once? For example, Shift+Ctrl+R?

I am sshing into OS X from a Windows client (PuTTY) and am wondering if I need to configure the client or is there a native way for OS X to emulate these commands on the receiving end.

  • It is about using terminal to send keyboard shortcuts. Specifically, I need to send ctrl+opt+shift+e. I need to do it without AppleScript, as it is from a Windows computer, using what I assume is some kind of Terminal simulator, or SSH from cmd. – user84019 Jul 1 '14 at 19:02
  • AppleScript works over SSH using osascript. The below answer is fully functional over SSH providing a GUI is present on the OS X machine. – grg Jul 1 '14 at 19:17
8

You can use AppleScript on the Terminal:

osascript -e 'tell application "System Events" to keystroke "r" using {control down, shift down}'
| improve this answer | |
  • When I try that, I just get a new line with ">"? – user84019 Jul 1 '14 at 19:33
  • Is it program specific? For example, if I want to type in "E" into TextEdit, would I type "osascript -e 'tell application "System Events" to keystroke "e" using {shift down}'"? – user84019 Jul 1 '14 at 20:59
  • 2
    Okay, I'm trying to type ctrl+opt+shift+e, and I have "osascript -e 'tell application "System Events" to keystroke "e" using {control down, shift down, option down}'" but it tells me "48:55: syntax error: A identifier can’t go after this “"”. (-2740)" – user84019 Jul 1 '14 at 21:03
  • Keystrokes are entered exactly as they would be if they were manually typed; they're not specific to each application. If you want to enter a keystroke within an application use `osascript -e 'tell application "AppName" to activate'. This will launch the application if it's not already open and also bring it the the foreground (i.e. it's name shows up in the menu bar). You can then use the code @grg provided in his answer above. – Peter Schorn Dec 30 '19 at 13:58
3

the cliclick shell tool is pretty awesome. sends keystrokes, clicks, all sorts of stuff

https://github.com/BlueM/cliclick

| improve this answer | |
  • boulder_ruby - an excellent solution, great reference. Are you the cliclick author? – Johnny Utahh Nov 24 '19 at 22:09
  • 1
    @JohnnyUtahh that's a negative, just a nerd obsessed with automation – boulder_ruby Dec 3 '19 at 22:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .