2

According to AppleScript documentation, I can create a notification with buttons by setting it to use alerts instead of banners in Notification Center preferences. But when I save an AppleScript as an app, then launch it once (assuming it has to launch to tell macOS it exists), it never shows up in the preference pane.

So as plan B, I tried scripting the app so that instead of a button, it does things upon activation. Works fine. According to this page, Mavericks would activate an app when you click on its banner, but that doesn't appear to work anymore in High Sierra; any mouseover or click just makes the banner persistent.

Plan C: command-tab to the app to activate it and run the subroutine. Here's the subroutine to wait for that:

on waitForActivate()
    set notFrontmost to true

    repeat while notFrontmost
        tell application "System Events"
            set frontApp to name of item 1 of (get processes whose frontmost is true)
            if frontApp is "test notifications 2" then set notFrontmost to false
        end tell
        delay 1
    end repeat
end waitForActivate

...which works, but is there a better way to have it wake than polling System Events once a second? Seems sloppy. I thought about saving it as stay-open and using an idle handler, but it's not clear to me how to make that any better at sensing its frontmost status quickly.

  • 1
    It appears for me in the preference pane. But I had to restart system preferences, can you confirm that after a restart of system preferences it still does not appear? – JBis Jun 12 '18 at 3:49
  • Indeed, restarting System Preferences does the trick – Andrey Gordeev Oct 19 '18 at 9:26

You must log in to answer this question.

Browse other questions tagged .