Launch app programmatically

Hello,

XOJO Version 2019 Release 1, macOS Catalina 10.15.7 (19H2)
I am trying to launch Disk Utility with the following code but it does not launch Disk Utility
SpecialFolder.Applications.Child(“Utilities”).Child(“Disk Utility.app”).Launch
What am I doing wrong?

Thanks.

Lennox

I’m currently not on a Mac, but I think since “Disk Utility” is a system application it’s no longer located in /Applications/Utilities (that’s on the writable Volume), but in /System/Applications/Utilities (the readonly system Volume).

Either way… I can only recommend to locate the app by BundleID.
Have a look at this example project: macOS App Directories.

1 Like

Thanks Jürg,
This, as per your recommendation, works…
SpecialFolder.System.Child(“Applications”).Child(“Utilities”).Child(“Disk Utility.app”).Launch

Thanks again,
Lennox

That hasn’t been a recommendation at all - just my best guess why your original code didn’t work as you’ve expected :wink:

Well… that will no longer work on pre macOS Catalina. And it may break again on a newer macOS version. It’s not our decision where a user (or Apple) stores an application.

That’s why I’ve recommended to look up the desired application’s location by it’s BundleID.

If your application is just for yourself, and you don’t care about all that (and are willing to “fix” your app because of such possible “external changes” again and again, if needed) - ok, fair enough.

For those interested in a more robust approach - see the example project linked above.

1 Like

OK, I will try it.

Thanks again.

Lennox

Thanks Jürg,

I am using XOJO Version 2019 Release 1, macOS Catalina 10.15.7 (19H2) and
macOS App Directories does not seem to be compatible with what I am using.

Thanks.

Lennox

Why do you think so? What are you exactly doing, and what’s happening on your end?
That example project is written using Xojo 2018r4.

If I download the Code (the “green button”) as ZIP, Debug-Run it - then it works as expected here.

I can then enter the desired BundleID:

Which locates the app. It then can be launched by double-clicking the result:

1 Like

Hi Jürg,

I am using the “XojoUnitDesktop.xojo_project”, when I launch it I get this message "You’re opening a file from a newer version of Xojo.’
I click “Proceed”
When I try to build it I get this message "…
An error occurred while compiling this project
Message: Can’t find a type with this name -
File: XojoUnitDesktop
Location: XojoUnitTestToolBar.RunButton
and 1074 errors 0 warnings

Don’t know what is happening

Lennox

That’s a completely different project :angel:

I have been mentioning the example project macOS App Directories.
It contains the Xojo project: macOS-App-Directories.xojo_project

If you click the link you get taken to the GitHub Website of the project.
From there you can click on the green button “Code → Download ZIP”. Then extract it, and open macOS-App-Directories.xojo_project in the Xojo IDE. The Readme has info about how to use this in your own xojo projects.

And I don’t care what is happening with that “other project” that has nothing to do with finding and launching applications :wink:

Hi Jürg,

I downloaded it and it works.

Thanks again.

Lennox