How to Automatically Press a Key on Mac at an Interval
Updated · by the ProMacTools team
Option 1: AppleScript
This presses Space (key code 49) every 60 seconds in whichever app is in front:
osascript -e 'repeat
tell application "System Events" to key code 49
delay 60
end repeat'
Terminal needs Accessibility permission (System Settings › Privacy & Security › Accessibility). Stop it with Control-C. It always types into the frontmost app, so it will interrupt you if you are working elsewhere.
Option 2: AutoKey
- Install AutoKey and allow Accessibility access.
- Pick a key (or record any key), the interval and how long to hold it.
- Choose a target app — for example a remote desktop window — or leave it on the focused app.
- Click Start. The menu bar shows when the next press happens.
In the default mode AutoKey brings the target app forward for a fraction of a second, presses the key and returns you to your app — after waiting until you stop typing.
Choosing a harmless key
If you only need to show activity, use a key that does nothing visible, such as Shift or F15. Use Space or Enter only when the app needs that exact key.