Wait for a process to finish launching

My application should wait for an applications to load completely. I have the process id of the application.


Do we have any function in Objective-C/swift to check if an application is launched?

Replies

My application should wait for an applications to load completely.

What platform are you working on?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

I'm using Mac Mojave 10.14.6 with Xcode 10.2.1

How long you are waiting for launching? We are also experienceing the same problem. It always shows that "your enrollment is being processed".

No, I'm not facing such issues.


Normally the first app starts in 3-5 secs. The second process should wait for the first app to launch.


But keeping a sleep is not a feasible solution and I'm looking for a way to find if the first app is launched successfully.

Can you modify the app being launched?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

No, I don't have access to modify the app that is being launched.


My app has to wait for Safari or Microsoft Office applications to launch properly before it start performing any of the operations.

The problem here is “launch properly”. There isn’t a universal definition of that term. For example, when you launch iTunes for the first time, it presents a modal alert requiring you to agree to its licence. Is it “launched properly” at that point?

The best suggestion I can think of right now is to send the app an Apple event. When and if it responds, you can be reasonably assured that the app’s main event loop is up and limping.

Weirdly, given that Apple events are so feature rich, I don’t think there’s a no-op Apple event you can use. One option would be to target the

current date
scripting addition. For example, the Apple event equivalent of this:
tell application "Safari"
    current date
end tell

You can prototype this with an AppleScript like this one, but I recommend that you distill this down to a single Apple event for production use.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"