Pause Until system event/notification - Shortcuts.app?

I'd like a macro to pause until a notification from a specific application appears.

Use case: Currently an app does not hide at log-in, even if set to hide in Login Items. A simple KM macro to hide all at login doesn't do the trick either. This is because the target app starts long after KM Engine, so it's not hidden.

Bartender.app displays a notification when all the menubar icons have been organised and each and every login apps are running.

With the desired condition, I could have the macro pause until a Bartender notification appears. This way I could ensure the KM macro "Hide All apps at Login" actually hides every single app.

EDIT: Title changed. Thanks to @Sleepy input I figured that it might not be possible at the moment. Although it would be interesting to see if there is any Shortcut.app integration that could be used to achieve this

Are you referring to the macOS notifications that appear in the upper right corner of the screen? I think so.

The best way to trigger on any macOS event is to get macOS to send a signal when that event occurs. However I'm not sure that macOS creates events that apps (like the KM Engine) can receive for these notifications. I think this came up once before, and the answer was that macOS doesn't provide that information to apps. (I searched for this discussion but could not find it, so I could be wrong.) KM can work with only what macOS provides.

However since the notification appears on screen, what stops you from writing a KM app that watches the screen for the notification, perhaps for 60 seconds after login? Then you could "see" the notification and take action. What's wrong with this solution? Or why not just insert a 60 second pause statement in a macro that triggers at login, and then hide the windows at that point? Wouldn't that do the job? I think it would.

Here's a thread that partly supports what I said:

However since the notification appears on screen, what stops you from writing a KM app that watches the screen for the notification, perhaps for 60 seconds after login? Then you could "see" the notification and take action. What's wrong with this solution? Or why not just insert a 60 second pause statement in a macro that triggers at login, and then hide the windows at that point? Wouldn't that do the job? I think it would.

Thanks for your input. What you said is true. I could simply use a "Pause Until" + "Found Image", although I find the "Found Image" macros a bit clunky.

In the long term, they tend to fail because of:

  • system/application updates that alter the GUI
  • resolution changes
  • switching between light/dark mode
  • window transparency alterations
  • multiple displays

For the aforementioned reasons I try to avoid them as much as possible. Most of those issues could be addressed by crafting a macro that accounts for the environment changes, but I'd rather find a way dependent on Apple Script, which is guaranteed to last longer and be snappier.

Of course AppleScript is better. But as the post which I cited above says, that's not possible. Apple makes it not possible. The issue here is how Apple makes macOS, not KM.

Some people want a 100% perfect solution, and in that case neither of my solutions will work for you.

Generally speaking, all of my solutions are under 100% reliable. I specialize in unreliable solutions, but at least my solutions tend to work most of the time when there is no 100% solution. Sometimes 80% is better than 0%.

Some people want a 100% perfect solution, and in that case neither of my solutions will work for you.

I am not looking for perfect, just exploring the possibilities. I appreciate your contribution.

I wonder if Shortcuts.app is able to read the System Notifications or other meaningful events related to the Login. If so, I could set it launch the KM macro via Apple Script and UID when the notification appears. I've tried googling around a bit, but without much success.

EDIT: I'm changing the title of the topic to make it more coherent with the specific use case

Exploring is good. I do the same thing.

Shortcuts might have access to hidden APIs, but I doubt it, because Shortcuts is a multi-platform app. Doing that would make it less compatible between different platforms.

The title change was a good idea. I was thinking of recommending that, but I didn't want to be be pushy.

Shortcuts might have access to hidden APIs, but I doubt it, because Shortcuts is a multi-platform app. Doing that would make it less compatible between different platforms.

I did not consider that, it sounds plausible.

I've heard that the MacOS app has way more options than the iOS one. So I will hold out hope.

Optimiscally someone with more Shortcuts.app knowledge will enlighten us. I am still learning KM and I am too lazy to dig through all the Shortcuts.app knowledge bases. Especially because I use it exclusively to trigger HomeKit automations at the moment. So I don't feel like investing too much mental energy in it.

As an alternative idea, if you're willing to wait for the Bartender notification to appear before hiding all your apps, what about having your KM "Hide all apps at login" macro pause for a roughly equivalent amount of time, say 30 seconds to a minute or so, before it executes the "Hide All Apps" action?

Yes, and the iOS Shortcuts can also do some things that macOS Shortcuts cannot do. They aren't supersets of each other. They have uniquenesses. (Shakespeare would approve of any new words I create.) But my overall impression is that Apple tries to make Shortcuts as consistent as possible across platforms. However notifications also exist in iOS, so maybe there's hope.

Yes, that's precisely what I meant when I wrote "Or why not just insert a 60 second pause statement in a macro that triggers at login, and then hide the windows at that point? Wouldn't that do the job? I think it would."

It would as long as the startup time doesn't change. It's more efficient than Found Image for sure, but I am happy to wait for more ideas

Maybe you can look into Bartender and get it to perform an action, like writing to a file, when it's finished. That way you can get KM to actually trigger on the creation of a file and it will work 100% perfectly and 100% as quickly as possible.

I don't have Bartender so I can't look into it. I think I have only two apps on my system: KM and Audio Hijack.

Maybe you can look into Bartender and get it to perform an action, like writing to a file, when it's finished. That way you can get KM to actually trigger on the creation of a file and it will work 100% perfectly and 100% as quickly as possible.

That would have been awesome, unfortunately Bartender cannot trigger any action at all

Ok, so you are saying that Bartender doesn't even write to any files for its own purposes? How strange.

Ok, so you are saying that Bartender doesn't even write to any files for its own purposes? How strange.

Not exactly. I just checked the settings and there's no option to trigger any action. If you are talking about something lower level than simple app features or settings I am all ears.

I found a website that says Bartender has lots of internal files. I think what you should do is monitor those files somehow and see which one(s) change(s) during the bartender boot process. Perhaps all you have to do is look at the timestamps. When a certain file's timestamp is "current", then the boot process is finished. That's how I would tackle this problem. That method will probably provide your macro with all the info it needs to know when Bartender is finished booting. I don't have Bartender so I can't really help.

Ah, so you already suggested that. I must have missed it when I scanned the thread before responding. Carry on.

Sounds promising. Would you be able to source the website?

This is what I could find, does anything look relevant?

com.surteesstudios.Bartender.plist /Users/alex/Library/Preferences
com.surteesstudios.Bartender /Users/alex/Library/HTTPStorages
com.surteesstudios.BartenderWindowHelper /Users/alex/Library/Containers/com.surteesstudios.BartenderWindowHelper/Data/Library/ApplicationScripts
com.surteesstudios.BartenderStartAtLoginHelper /Users/alex/Library/Containers/com.surteesstudios.BartenderStartAtLoginHelper/Data/Library/ApplicationScripts
com.surteesstudios.Bartender.BartenderQuickLookExtension /Users/alex/Library/Containers/com.surteesstudios.Bartender.BartenderQuickLookExtension/Data/Library/ApplicationScripts 
com.surteesstudios.BartenderWindowHelper /Users/alex/Library/Containers`
com.surteesstudios.BartenderStartAtLoginHelper /Users/alex/Library/Containers
com.surteesstudios.Bartender.BartenderQuickLookExtension /Users/alex/Library/Containers
com.surteesstudios.Bartender /Users/alex/Library/Caches

Bartender Show Full Menu Bar /Applications/Bartender 4.app/Contents/Resources/Bartender Show Full Menu Bar.app/Contents/MacOS
Bartender.sdef /Applications/Bartender 4.app/Contents/Resources
BartenderBarWindowController.nib /Applications/Bartender 4.app/Contents/Resources
Bartender.nib /Applications/Bartender 4.app/Contents/Resources
Bartender Show Full Menu Bar.app /Applications/Bartender 4.app/Contents/Resources
BartenderQuickLookExtension /Applications/Bartender 4.app/Contents/PlugIns/BartenderQuickLookExtension.appex/Contents/MacOS
BartenderQuickLookExtension.appex /Applications/Bartender 4.app/Contents/Plugins
Bartender 4 /Applications/Bartender 4.app/Contents/MacOS
BartenderStartAtLoginHelper /Applications/Bartender 4.app/Contents/Library/LoginItems/BartenderStartAtLoginHelper.app/Contents/MacOS
BartenderStartAtLoginHelper.app /Applications/Bartender 4.app/Contents/Library/Loginltems

I don't know what that phrase means. But I can still explain things.

The most likely solution is for you to look at the timestamps on all the files in Bartender's folders. Whichever one gets updated last during the Bartender startup process is most likely the best one to check.

Bear in mind that macOS has three different timestamps on each file: the time a file was created, the time it was last modified, and the time it was last accessed. The latter two are the important ones for your situation.

The command "ls -lt" will list files by date modified (most recently modified first, which is what you should examine.)

The command "ls -lu" will list files by date used (most recently used first, which is what you should examine.)

If you see one that's modified during the startup process, then that's the one you should try examining during your macro which starts when KM is launched. Bear in mind that you. may have to try more than one file, because Bartender may modify or access the same file more than once during its startup process. What you are looking for is a file that is accessed or updated only once, near or at the end of the process.

Yes, this takes some legwork. But that makes it rewarding, and this could make it work extremely reliably and accurately, compared with some of the other ideas we've discussed.

Hey Alex,

I think I'd poll the process list for the desired processes.

Use the %Application%All% token and test for contains text app1, app2, app3...

Put it in a loop, give it a reasonable pause at the end, and maybe a short pause after the loop condition tests true.

If the token doesn't show all the necessary processes try this AppleScript:

set AppleScript's text item delimiters to linefeed
tell application "System Events"
   name of every process as text
end tell

You could also use a shell script with ps or top.

-Chris