at command with osascript broken after Mojave

I had a script as simple as this on a .sh file:

echo 'osascript -e \"display notification "Warning after a minute\""' | at now +1 minute


After upgrading to Mojave the script was no longer working, it doesn't work even on the terminal. I get no error messages, the notification simply don't show up after the scheduled time is reached. If I simply run the osascript it works, but along with at command it doesn't: osascript -e "display notification \"Warning after a minute\""


Ideas?


I've tried different syntaxes, but they all behave exactly the same, "at" is scheduled but no notification:


at now +1 minute << \eof1

osascript -e 'display notification "Warning after a minute"'

eof1



at now +1 minute << 'END'

osascript << 'END1'

display notification "Warning after a minute"

END1

END

MacBook Pro Retina (2015 and later)

Posted on Jan 11, 2019 5:43 AM

Reply
Question marked as Top-ranking reply

Posted on Jan 11, 2019 7:26 AM

The problem is that you have to enable atrun.

This is supposed to be launched by launchd to take care of your at queue.


As far as I can tell, making this work requires at least two or three things in Mojave:


1) Grant Full Disk Access to /usr/libexec/atrun - in System Preferences->Security & Privacy, click "+" and add it to the list (press Command-Shift-G and type the /usr/libexec path, since it is hidden in the normal navigation windows)



2) Activate the service in the plist: /System/Library/LaunchDaemons/com.apple.atrun.plist


By default, this is inactive, because of these lines (lines 13 and 14 on my mac):


    <key>Disabled</key>


    <true/>


Now editing this file, even with sudo, fails because of SIP... I will not disable SIP for the purpose of testing, but you might have to. Change <true/> to <false/> or remove these two lines altogether.


3) Load the service:


sudo launchtl load -w /System/Library/LaunchDaemons/com.apple.atrun.plist


Hopefully, this will restore the at functionality. As I said, I am not going to test this, but if you do:

a) make sure you restore SIP after you do step 2

b) tell us about it!

4 replies
Question marked as Top-ranking reply

Jan 11, 2019 7:26 AM in response to leandro113

The problem is that you have to enable atrun.

This is supposed to be launched by launchd to take care of your at queue.


As far as I can tell, making this work requires at least two or three things in Mojave:


1) Grant Full Disk Access to /usr/libexec/atrun - in System Preferences->Security & Privacy, click "+" and add it to the list (press Command-Shift-G and type the /usr/libexec path, since it is hidden in the normal navigation windows)



2) Activate the service in the plist: /System/Library/LaunchDaemons/com.apple.atrun.plist


By default, this is inactive, because of these lines (lines 13 and 14 on my mac):


    <key>Disabled</key>


    <true/>


Now editing this file, even with sudo, fails because of SIP... I will not disable SIP for the purpose of testing, but you might have to. Change <true/> to <false/> or remove these two lines altogether.


3) Load the service:


sudo launchtl load -w /System/Library/LaunchDaemons/com.apple.atrun.plist


Hopefully, this will restore the at functionality. As I said, I am not going to test this, but if you do:

a) make sure you restore SIP after you do step 2

b) tell us about it!

Jan 11, 2019 12:21 PM in response to Luis Sequeira1

Thanks again @Luis Sequeira1, this almost fixed my problem. The at command is finally working, but for some reason the "display notification" is failing.


When I run:

echo 'osascript -e "display notification \"testing\""' | at now +1 minute


I get a new email saying:

osascript[2030:51658] NSNotificationCenter connection invalid


on the internet I found people saying they've installed "reattach-to-user-namespace", "gem install terminal-notifier" or "pip install ntfy", but I'd rather not go down that path... any other suggestions?

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

at command with osascript broken after Mojave

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.