MacOS – Launch app in foreground doesn’t work from cron, but does from terminal


I have the following:

* * * * * open -a /Applications/  ~/notes.txt; open /Applications/

Neither of the 2 apps brings focus to the foreground (though they do get launched in the background) so the whole job is a bit pointless (it's to remind me to make some notes at the end of each day at work).

It works if I copy and paste the commands into a terminal. So why does cron behave differently and can this be changed?

Best Answer

For me on macOS High Sierra, e.g.:

 * * * * * open -a TextWrangler ~/notes.txt; open -a Notes

works as is, both apps come to the front.

Try adding, e.g.:

; osascript -e 'tell app "TextWrangler" to activate' -e 'tell app "Notes" to activate'

to the end of your existing command and see if that makes any difference, e.g.:

* * * * * open -a TextWrangler ~/notes.txt; open -a Notes; osascript -e 'tell app "TextWrangler" to activate' -e 'tell app "Notes" to activate'