22
loading...
This website collects cookies to deliver better user experience
cron
and how it can run scripts periodically – I figured this would be the tool to save me here.crontab -e
):*/5 * * * * open --hide --background /Applications/RescueTime.app
open
for ResuceTime command every 5 minutes. The --hide
and --background
ensure that the application doesn’t open in an obtrusive manner (i.e., think applications with a GUI).cron
would trigger… If I had to take a guess, the open
was causing focus to switch briefly and would interrupt keystrokes on the current application I was in.open
from triggering multiple times during the day.# Scroll to see full command (it is one line due to fitting in the crontab)
*/5 * * * * app=Rescuetime; ps aux | grep -v grep | grep -ci $app > /dev/null || open --hide --background /Applications/$app.app
app=Rescuetime;
sets a variable of what application we’re trying to keep open.ps aux | grep -v grep | grep -ci $app > /dev/null
lists all running processes, excluding the grep
process, and finally counting the found lines while grep
ing for the application’s name. This ends up being a 0 or 1. The STDOUT output is directed to the void so that it doesn’t create new mail
entries.||
will conditionally run the next statement if the previous was falsey (i.e., no application was found running)open --hide --background /Applications/$app.app
opens the specified applicationopen
).