Startup Launching - when are all previous projects open?

I'm refining a KM macro for managing my startup app launches -- When I launch Curio, it automatically opens the projects that were open when it quit. That's very convenient, except I haven't found a way to determine when it's done opening projects, and its processes interfere with other apps starting up.

I thought of having KM wait for a particular menu item to activate, but there's nothing that stays inactive while Curio opens the projects.

The only idea I could come up with is kind of above my pay grade:

  • At Quit, collect the name of all open windows to a text file saved to disk;
  • On launch, have KM loop to wait until all the window names exist as menu items in the Windows menu.

It feels kind of brute force, but I can't see another way to detect when Curio is done opening projects.

I'd appreciate any help or guidance. Cheers.

May I ask what your purpose is in waiting for all projects to open? Sometimes when the reason for a request is explained, we can sometimes find other solutions.

Your idea isn't bad. Although you didn't state in your first bullet whether you want to create a macro that you trigger to close the app, or whether you want the KM Engine to detect when the user is closing the app.

Sometimes there are other approaches to problems like this.

  • For example, if Curio opens up the projects in some order, like alphabetical order, then you wouldn't have to wait for all the projects to open, you may only have to wait for some project called "Zzzz" to open.
  • Or, for example, if you time how long Curio takes to open all its projects, and add 10 seconds to that, you could simple create a KM macro that triggers upon the activation of the app, and then waits a fixed period of time and then does whatever it is you want to do.
  • Or for example, you could create a macro that triggers upon the activation of the app, then, repeatedly, for a period of time, fetch the list of all open windows (this requires AppleScript, I think) and then decide that your app has finished launching all its windows once a certain period of time has passed after the list of all open windows is no longer growing.

I like the last idea above. Of course, for the last idea, this probably means that you can't have people clicking in different apps while Curio is opening its projects. If they did, that could mean a different list of windows is returned. So I'm not sure if this is acceptable to you.

How long does it take Curio to open a project? Could you, for example, do a pause-check-pause-check... until the count of open Curio projects remained unchanged?

Yes, that's even more brute force than your idea of saving a list of projects on Quit. But it's a lot less work :wink:

Alternatively, if the problem is merely that Curio is interfering with other apps opening -- can you move Curio to the end of your startup routine? Then there's no more opening apps to interfere with!

During my tests, I have found that when apps are loading their files, they are using a lot of CPU time (5% to 50%), and when they are finished loading files, their CPU time drops to under 1%. So it wouldn't be too hard to write a macro until an app is "under 1% CPU for more than 5 seconds." You just have to get the process ID for the app, then check the CPU usage for that process using a macOS command, probably "ps".

Thanks for your help!

I just got a solution that works:

One of our KM bretheren on the Curio forum gave me a good suggestion, to do it in AppleScript, saving a list of open documents on Quit and then comparing on Launch. Comparing by name was problematic because some of my document titles contain emojis. So I ended up saving a list of names on Quit, then on Launch, counted the names and compared the counts instead of the titles. That worked.

P.S. - I know next to nothing about AppleScript, so I had ChatGPT code it for me, and it did a pretty good job.

1 Like