How Can I Tell When Startup is Complete?

When I reboot, either manually or "accidentally", I have my Mac set to reopen all windows. I want to be back where I started. There are over a dozen apps that get restarted this way, Including the KBM Editor.

How can I tell when this process is complete, so that I can start something else? In particular, I want to clean up the various apps that don't restart exactly the way that I want them to. I want that cleanup to happen as soon after reboot as possible, otherwise I could just set a timer for 10 minutes.

It appears that there is a particular order in which everything gets restarted. Keyboard Maestro is somewhere in the middle. On reboot I can watch multiple apps, which had been in different Mission Control Desktop Workspaces (Spaces/Desktops) start up in Desktop 1. Then the KBM Editor starts, and it reopens in the same Desktop that it had been, Desktop 12 in my case. The apps that get restarted after KBM then open in that Desktop Space, instead of in Desktop 1. Again none of them actually belong in the KBM Desktop any more than they belong in Desktop 1.

The order in which the apps open, and whether or not they open before or after KBM, seems mostly consistent. But is that consistency because that's the order they were opened in at the last reboot? Or is there some other prioritization at work? Are apps able to tell the system whether they should be restarted early or late?

I thought of checking for all my usual apps, using something like

image

But not all my typical GUI apps will necessarily be open at shutdown and thus be restarted at reboot. And there are apps with no windows that I have little clue of where there are in the startup order. One GUI-less app that is usually always restarted is WhichSpace.Because WhichSpace has a Toolbar icon, I can see that it starts up relatively late in the process. Is there any way of finding it in a Startup list somewhere and seeing if there are any entries after it?

If there was some app that was always started last, which I could somehow know would always be the last app to be started on a reboot, then I could have my KBM cleanup macro wait until that app was active and then be able to run in confidence.

Is there any way to examine what the app restart order might be? Is there any way to manipulate the order? Is there any way for me to force an app to always start last, maybe an app of my own creation?

Alternately, is there some system API flag, possibly named something like NSSystemRestartHasCompleted, that I could test?

Ideas welcome.

Since you specifically say that you don't know which apps you must wait for, then your KM macro will need to examine the list of apps that will start up at login. That list is VERY large (thousands of apps start up when you login) and there are actually FIVE different lists stored in five different locations. For a decent summary of the locations, you can watch this video:

It's unlikely that macOS has an "order." Your idea of waiting for the "last" app probably won't work since there is probably no "order."

That wouldn't solve your problem because you don't want to wait for all the apps to be launched, you want to wait for all apps to be finished their setup process after they launch. MacOS has no idea when any app is "ready". All MacOS would know is when it has initiated the launch, not when the app is ready for the user to use.

Some apps that are launched at login show their presence in System Settings under General, Login Items. Many apps don't bother showing themselves in that list, so it may not help you. Even so, that's a GUI interface. What you probably want is a text interface. You can possibly get the lists of apps using the "defaults" app in macOS, but I didn't check that yet.

What do you mean by ' "accidentally" '? Is this something that happens often?

Yeah do that.

Bearing in mind what you said about your Chrome workflow: you didn't mean 10 hours? :stuck_out_tongue_winking_eye:

Maybe something like this..?

Make a macro, triggered by the launch of the KM engine, that closes the applications you wish to manage (if they're open) and then opens them in the order you want.

If you know the apps you need to clean up after a restart, how about a macro or Group of macros that is enabled on login (you can add an uptime check if you log in/out outside of restarts), monitors for those apps or is triggered by their launch, and quits/clean-relaunches them for you. Self-disabling n minutes later.

Or turn that upside down and quit/clean-relaunch any app that opens except those on your list of "known good".

1 Like

Thanks @Airy,

Is there a specific order in which those five listed are triggered? Could I wait for an app on the fifth list and be able to mostly trust that apps on the first four lists are already running?

Fortunately, all I need to be concerned about is the GUI apps that I typically use. Your pointer:

is a good start, at least for my reference of which ones I might be trying to deal with. The other list, that presumably varies from reboot to reboot, is the one generated by the option, "Reopen all windows on restart". Those are the ones I'm trying to get a handle on.

Thanks, @kevinb,

I'm not really concerned about creating a startup order, I just want to know when the whole process is complete — so that I can start the cleanup routine without having it interrupted by additional apps starting up along the way. That's why I can't just do it when KBM starts up, there are numerous apps that start up after KBM does and I'm trying to know when I can start cleaning them up, without having to wait overly long to get back to what I was doing before the system crashed or I was forced to reboot. With your method, I still have the unknown wait time to deal with.

Thanks @Nige_S,

That's kind of the direction I have been leaning. I have been hoping to find a "simpler" method that wasn't dependent on my doing a lot of waiting and testing and custom handling of apps and their windows. With all the discussion and the clarity that has brought to whatt the real issues are, I don't think there's a way around it.

I think the most problematic app is Preview. and I cannot think of a simple way to manage it. I didn't really describe that problem in the OP, I was just looking for when I might run a solution, if I came up with one.

Unlike some other Apple apps, e.g., TextEdit and Notes, Preview does not remember which desktop its open windows were in. TextEdit is very well behaved; it will even reopen unnamed, unsaved windows in their original desktops. But Preview reopens every file in just one desktop, whichever happens to be the "current" desktop at the time Preview opens. Sometimes that's Desktop 1, sometimes that's my KBM desktop, sometime the desktop that got activated by some other app which opened in its "correct" desktop, like whatever was the last Finder window to open.

Of course the problem is worse with Preview than with some other apps because which files are open is pretty volatile and variable. The only way I can think of to manage it would be to create my own list of which files Preview has opened and which desktop space I want them to be in. Then whenever Preview does open, I look at the newly opened files and compare them to the saved list of files and locations, whatever has a known desktop that it belongs in gets automatically moved. Then I only have to manually move the unknown files to their proper location, and automatically add them to the list. A list of a few hundred files should not be unmanageable and I can periodically purge it.

And it's a fair bit of work. Is Preview's annoying startup behavior enough of an annoyance that it's worth that work? I don't know.

Maybe I should have spelled it out but I took it as read that your macro would use pause and other actions as necessary. @Nige_S communicated the line I too was thinking along, more successfully, and in detail. The point about the trigger was not to do everything at startup but just to be ready to get going as soon as possible.

Certainly you would need to know what the real slowcoaches were – as I imagined such a macro.

It's a shame that using all those spaces/desktops causes you so much work when things go wrong. I find them confusing enough at the best of times! For that reason, I can't test this, but I wonder whether any suitable alternative to Preview (such as Skim perhaps) might be better behaved. Otherwise – no idea. Good luck!

TL;dr: This is not a huge issue.

The support that multiple desktops gives to my sanity, especially now that I have my basic naming and movement macros functioning reliably, is definitely worth it.

If I had been comfortable with fewer than 16 desktops, I probably would have stuck with @_jims' MACROS: Desktop Spaces • Macros to Improve Navigation and Window Management, v3.0.

But then I discovered that, when using an external monitor I could make 16 desktops in each monitor, and then I could move the existing desktops between monitors, and they would all still be there (except one, the first desktop on the external monitor) on the laptop alone, when I unplugged the monitor. So now I have 45 on my laptop.

I had already been spoiled by using (no longer available) CurrentKey Stats, which allowed me to name each monitor with text, like Jim's menu, and which allowed that name to follow the desktop if you rearranged the order (which Jim doesn't do, his movement is based on Mission Control Shortcuts that work by absolute positional order of the desktops). CKS also allowed you to move a window to a new Desktop simply by holding on to the title bar while you moved, the same way Mission Control does (but which Jim has to use different hotkeys to do) so I tried to see if I could implement all those features myself.

I was limping along with an AppleScript observer to watch for changes of desktop, but that took repeated manual intervention to keep it going which was a discouraging time-suck. I never did figure out why that observer stopped watching, but I frequently had to kill it and restart it. KBM v11 added the Space Changed trigger and that moved my system into "it just works" reliability.

So now I'm banging away at fine tuning the UI and at trying to fix the petty annoyances that mostly bother me when I have to reboot, as well as banging at the primary cause of reboots: too many Chrome tabs open. I'm pursuing a way to keep track of the open Chrome tabs on a Desktop by Desktop basis. I haven't found any way to access that info programmatically, but Chrome does keep track of it somewhere because when I have to reboot, Chrome usually asks "Reopen all previous windows?" or something like that, and when I do, all the windows reopen in their original Desktops.

But if too many tabs was the proximate cause of the crash or hang, that's not really an effective solution. So I'm looking for ways to put Chrome windows away, "on hold", Desktop-by-Desktop, because I haven't found any bookmark managers or tabs managers (including my favorite, Tabs Outliner) that can do that.

Sorry for the digression. Your comment just got me thinking about the whole history of the last couple of years at this.

It really doesn't matter, because your stated aim was to determine "when the [startup] process is complete." As I said, macOS, doesn't know when the startup process is complete. It has no way of knowing. All it knows is when it "launches" the app. It can take seconds, sometimes even minutes, for any particular app to have "completed" its launch and made itself ready for user input.

But if you change your mind, and you don't really care about whether your apps are "ready", then you can easily just look at the list of processes resulting from the "ps" command. That will tell you when they have been launched. But then you also stated that you don't know which processes you need to wait for ("But not all my typical GUI apps will necessarily be open at shutdown and thus be restarted at reboot") so even this won't help too much.

It's really interesting to me how differently people's brains work with operating systems. First off, the following is not saying "you're doing it wrong," in any way—whatever works for someone is the right way to do it! It's just something I find interesting about OSes and people, the way some features drive such different reactions from users.

Personally, if I have more than one Space, it drives me absolutely bonkers. Even when I have 80 windows open with 200 tabs in my browsers, they're all open on one Space—I don't want to have to go somewhere to find my windows, I know they're all here. But I also never shut down or reboot unless forced, and my desktop Mac always has two displays connected. So my setup is stable in that regard.

I use tools to make managing multiple windows easier for me, but I tried Spaces (many times) and my brain just does not like the jarring jump from one Space to another, nor does it like not finding a window where it fully expects the window to be :).

Stage Manger is another such feature; I won't ever use it, and the one time I tried it, it drove me crazy with what it was doing. But I know people who swear it's the greatest thing they've ever used in computing. :slight_smile:

-rob.

1 Like

Thanks. It starts on Ventura, MacOS 13 and I'm still on Catalina, 10.15. Not yet a motivation to try OpenCore Legacy Patcher.

The list of apps that will be re-launched following a restart can be got with

defaults -currentHost read com.apple.loginwindow.plist TALAppsToRelaunchAtLogin | grep "Path"

...while your account is logged in. What I don't know is how long that list persists after restart/login -- you'll be able to use it if the "previous session" list is still available after the KM Engine launches, otherwise you'll have to find a way to either keep your own, persistent, up to date copy (periodic macro?) or write your own LaunchDaemon to grab one on machine start and before user login.

Easy enough to check -- write a KM macro, triggered by login, that writes the results of that command to a file. Then wait for the next "accidental" restart...

That would, at least, give you a list of "apps that will be re-opening" to check against, avoiding the "and now wait 10 minutes..." bit of any restart macro.

Most of the other problems seem to be issues with apps/windows in Spaces. I suspect that's a per app issue, not something that can be got from the plist, but try the above command without the grep and see if there's anything that will help.

Thanks @Nige_S,

I just tried the command, saw that App Store was in the list, quit App Store, and re-ran the command. No App Store the second time. Cool. Definitely potentially useful.

As you suggest, it may take a trick or two to have that list of what should restart still be available after a restart. And too bad that list cannot be counted on to be in chronological order.

Erm... chronological order of what? Even if it was time-ordered, it doesn't seem to matter here what order apps are restarted in, but when they're ready to be "worked with" -- launches are concurrent, so a light-weight app will be ready before a "monster" even if it's later in the launch list.

Right. I keep forgetting that and tend to think of as a sequence of commands in a script or a macro, sequenially waiting for the previous command to finish before doing the next one.

I guess "ready" means something like "app is running and has a window open" (maybe plus two seconds or something). It looks like the core puzzle is how to wait for apps that are going to open and not wait for apps that are not. That list from TALAppsToRelaunchAtLogin seems like the right starting point, IF the previous list can be accessed after reboot, as you pointed out.

Maybe that list could be copied every 60 seconds. Not a huge overhead, I would hope, and if the system crashes or freezes less than 60 seconds after launching an app, maybe I don't want that app part of the restart.

Thanks for all the help; this feels like a productive direction and pretty straightforward to implement. However, I'm going to have to put this on the back burner for a few days or a couple of weeks. I'll be back when I make some progress.