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:

  • Wow, over 1000 views and only 2 likes for the question and 1 for the answer?! Commented May 18, 2017 at 6:43

1 Answer 1


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
  • To be a nitpicker, this is an UNIX-style solution: creating a launchd LaunchDaemon would be the ideal method (giving you the ability to easily suspend these launches and resume them on demand if such a need would arise, too) :)
    – Ryccardo
    Commented Apr 3, 2013 at 22:35
  • You say 'UNIX-style solution' like it's a bad thing. IMO it's much easier to suspend these launches and resume them on demand by commenting and uncommenting the relevant line. I thought stackexchange wasn't the place for religious wars! Commented Apr 4, 2013 at 20:37
  • 1
    It isn't inherently a bad solution at all (just like I prefer manually created symlinks to Finder aliases); it's just a different way with some advantages and some disadvantages, almost like opening a currently selected file with Command+O, Command+Down, double clicking, the File menu or the contextual menu :)
    – Ryccardo
    Commented Apr 4, 2013 at 21:06

You must log in to answer this question.

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