How to root launch a regular Mac application from a cron job in /etc/crontab

cronlaunchdsudo

I want the cronjob to do some things as the superuser, and depending on the result, launch an app as me, the logged-in user.

I've tried a bunch of things but nothing I think should work does.

Similar questions:

Best Answer

I figured out the key was to use su with -l, -c and single quotes:

su -l myloginname -c '/usr/bin/open -a [App].app'

In context:

*/15 * * * * root if { !  /usr/bin/diff  /var/tmp/foo /var/backups/bar >> /var/log/foobar-diff.log ; } ; \
then  /usr/bin/su -l myloginname -c '/usr/bin/open -a /Applications/iProcrastinate.app > /dev/null 2> /dev/null' ; \
/bin/date >> /var/log/foobar-diff.log ; fi