Launch an application from Cocoa application

Hi, ALL,

I'm trying to find out how do I open an application from my own one.


I was looking at https://developer.apple.com/documentation/coreservices/launch_services?language=objc but it looks like I can't do that since all those useful functions are deprecated now.

I also want to get a notification of this task be finished inside my application.


It looks like in Cocoa I can open URLs only with the browser, because everything else is Carbon and is deprecated since 10.10. Moreover, there is no good documentation about lauching services in Cocoa, as the documentation itself points out to Carbon. as if in https://developer.apple.com/library/archive/documentation/Carbon/Conceptual/LaunchServicesConcepts/LSCIntro/LSCIntro.html?language=objc#//apple_ref/doc/uid/TP30000999

NB: I don't want to open a document - I want to open an external application, that will perform some task for me.


So - can someone points me to either a good (recent) Coca version of this documentation or just simply provide a code on how to start a program/service in Cocoa and get a notification about it.


Thank you.

Could you launch it from a shell command ?

h ttps://scriptingosx.com/2016/04/build-an-application-to-run-a-shell-command-in-xcode-and-swift-part-1/


Or

h ttps://www.hackingwithswift.com/example-code/system/how-to-run-an-external-program-using-process


You could also have a look at resources listed here:

https://stackoverflow.com/questions/35339277/make-swift-cocoa-app-launch-on-startup-on-os-x-10-11


They are 2 year old, but could help.

These functions are not marked deprecated as of 10.15


1 - LSCopyApplicationURLsForBundleIdentifier : gets an application URL(s) given a bundle identifier. Actually, gets an array of URLs for all applications that can handle that bundle identifier registered in the LaunchServices database. In 10.15, it is sorted by the "bestness" of the application. Note that you may need to register your helper application with LaunchServices.


2 - LSOpenCFURLRef : Opens a URL pointing at the application you want to open. URL is formatted as Core Foundation URL.


3 - LSOpenFromURLSpec : Another option for opening a URL.


The opening functions seem to be synchronous in that the function doesn't return until the applications is running, or an error is returned. So, your notification that it is running is a successful return code from the open call.


There a lots of nuances that you need to understand by reading the LaunchServices documentation (using the links). The older documentation is still useful for background and concepts. If your "application" is a raw executable, not an application bundle, you have the Process and C-library routines as well.

The bundle identifier would be the bundle identifier for your helper application.

It would be better if you would clarify exactly what you want to do instead of list some deprecated functions.


Without that information, no one can answer your question.

If you just want to launch an application, you can do it with NSWorkspace

If you want to launch a command-line task, you can do it with NSTask


There are benefits and tradeoffs to each approach. There are also some more esoteric ways to launch other processes. You did say "services" which implies you might be interested in one of those funky things.

Launch an application from Cocoa application
 
 
Q