at + cliclick
You can use cliclick to execute your key presses and at
(ships with macos) to schedule the execution of the command.
echo 'cliclick kp:"volume-up"' | at 09:00
If you want to schedule an event like to occur at some regular interval (e.g. some time every day, on Mondays, the first of each month, every ten minutes) you can use crontab. Open up the crontab list of jobs with crontab -e
in a terminal. Then put in an entry like:
0 0 * * * cliclick kp:"volume-up"
Here are the man pages for at and cron if you want to see more details about how to get the behavior you want.
but first!
If you can run other at
jobs but using cliclick with one is causing problems, just write a shell script with the command in it and run that with at
. e.g:
echo 'zsh ~/clicktest.sh' | at 13:00
I also had problems just getting at
to work at first. Apple seems to have made it pretty difficult to use at
. You have to run the following command as root to enable the atrun
program (which processes at
jobs):
launchctl load -w /System/Library/LaunchDaemons/com.apple.atrun.plist
(To run it as root use sudo su
to switch to root and then switch back with exit
)
... just in case
Just to be safe I altered the file from the launchctl
command - /System/Library/LaunchDaemons/com.apple.atrun.plist
- changing the entry "Disabled" to false.
Since this is a read-only volume you need to have SIP turned off and then use mount -uw /
to make it writable. Then you have to change the permissions on the file to make it writable. e.g.
chmod 777 /System/Library/LaunchDaemons/com.apple.atrun.plist
Then change the permissions back to their previous state or the OS will complain when it goes to load the plist again:
chmod 644 /System/Library/LaunchDaemons/com.apple.atrun.plist
I don't think you need to do all this I just did it because I was worried it might not launch atrun
automatically on boot unless I changed the plist.