More than one Applications path under some macOS systems

So I have an odd case there one user could not use a button I created that essentially just looks for another App (I created), Open it and then Quit the App that initiated that action.
The code is super simple:

Var ERun As FolderItem #If TargetWindows Then ERun = specialfolder.Applications.Child("MyCompany").Child("MyApp.exe") If ERun <> Nil and ERun.Exists Then ERun.Open Quit Else Window1.Messages_Area.Value ="Can't find MyApp in: " + ERun.NativePath +EndOfLine+" Please make sure you installed it and try again" End If #endif #If TargetMacOS Then ERun = specialfolder.Applications.Child("MyApp.app") If ERun <> Nil and ERun.Exists Then ERun.Open Quit Else Window1.Messages_Area.Value ="Can't find MyApp in: " + ERun.NativePath +EndOfLine+" Please make sure you installed it and try again" End If #endif

I asked the user what text appears in the ‘Messages_Area’ and he said: “Can’t find MyApp in: /System/Applications/MyApp” …
This is so odd as I was under the impression that Specialfolder.Applications will always point to the actual Applications that in use (/Applications/MyApp.app) and to my surprise I now realize it is not that definite and macOS has more than one Applications path, but more importantly that Xojo may point to wrong one ending up with Nil FolderItem.

I ended up writing this:

Var ERun As FolderItem #If TargetWindows Then ERun = specialfolder.Applications.Child("MyCompany").Child("MyApp.exe") If ERun <> Nil and ERun.Exists Then ERun.Open Quit End If #endif #If TargetMacOS Then ERun = GetFolderItem("/Applications/MyApp.app", FolderItem.PathTypeShell) If ERun <> Nil and ERun.Exists Then ERun.Open Quit Else ERun = specialfolder.Applications.Child("MyApp.app") If ERun <> Nil and ERun.Exists Then ERun.Open Quit End If End If #endif
It works but it feels wrong to me, am I missing something?
Can I make sure Xojo points to the “right” Applications folder on macOS with one “bulletproof” line of code?

[quote=492473:@Sagi Gal]So I have an odd case…

It works but it feels wrong to me, am I missing something? [/quote]
It’s expected actually. In the migration toward making macOS as useless as possible, Apple adopted the “protected system apps” idea and stores those in their own Applications folder.

Funny and yet so typical to Apple :wink:
But that still doesn’t explain why Xojo would point to the ‘protected system apps’ (/System/Applications) instead of the ‘open for developers’ applications folder when I use specialfolder.applications while the documentations specifically say it points to /Applications under macOS, should I report it as a bug ?

To me, this is more a feature request: feedback://showreport?report_id=57672 SpecialFolder - get all possible Application(s)Directories

And possible workarounds are in this example project: App Directories
I recommend to search by BundleID on macOS. But the example shows other ways, too.

Hi @Jürg Otter thanks for your insight!
I see why you would say you see it as a FR but you expect it to return all existing locations while I only want it to return the “right” one (the Default user Applications folder) but it goes to the system protected applications folder, then to me it’s still a bug even though your FR would help fixing that bug along the way.

Problem is there isnt just one “right one” any more

If you’re using SpecialFolder.Applications to look for an application which one is “right” ?
Both may be

Here I would agree with Jürg that you should use the bundle ID but …

Don’t use the path to get the app. Use the bundle id to find out if the app is installed. With the bundle id you can get the location. Independent of Crapolina stupidity.

[quote=492494:@Norman Palardy]If you’re using SpecialFolder.Applications to look for an application which one is “right” ?
Both may be[/quote]
Well if you look in the default user Applications folder you’ll see that all the system protected applications are there as well while in the /system/applications you have only the system protected ones, so I would say default user Applications folder is the ‘right’ one but now that we have a situation where we have more than one Applications path we need to have multiple SpecialFolder.Applications such as SpecialFolder.UserApplications and SpecialFolder.SystemApplications

And what about ~/Applications ?
Or /Users/Shared/Applications ?

There are at least 4 places applications can be located - hence why using the path is not the right way
The bundle ID will work regardless

[quote=492498:@Norman Palardy]And what about ~/Applications ?
Or /Users/Shared/Applications ?

There are at least 4 places applications can be located - hence why using the path is not the right way
The bundle ID will work regardless[/quote]
You’re absolutely right I just don’t know how to get the app location by using the bundle ID :frowning:

Thats what the forums are for :slight_smile:
The answer on this thread contains what you need
https://forum.xojo.com/9797-how-to-test-whether-an-application-is-installed-macos#

The example project mentioned above includes this, too…

And it shows a way to search just for the app name (String), such as you’ve tried in the original post, but will respect both/all standard/default application directories.

Many Thanks @Jürg Otter , I’ll make sure to look into it too :slight_smile:

I presume you’ve used the Finder to see this, right?
When you go into “/Applications” in the Finder, it shows you both “/Applications” and “/System/Applications” in the same view (a “convenience” so that you can use either group of apps without having to guess the correct folder). But, on disk, they are still separate folders and none have the content of the other.

Most of these “Applications” folders follow the same logic as other MacOS folders. In MacOS X, you basically have 4 domains: system, local, network and user. You may find “commonly named” folders in any of these domains (just consider /Library, /System/Library /users//Library, or subfolders like “Preferences”; they all serve the same purpose, only for different OS “domains”).
“Applications” folders apply the same concept (/Applications and /Users//Applications may exist, for instance); it’s just that, prior to Catalina, /System/Applications was simply not yet “implemented”.

Norman also mentions /Users/Shared/Applications, which I’ve never encountered before (and, in my 10.14 installation, it doesn’t even exist). I’m not sure whether this is a MacOS folder or one created by some custom applications. Also, if it’s a MacOS folder, I’m not sure from which “domain” it would belong, should it be accessible from declares at all.

By browsing the MBS documentation (e.g. https://www.monkeybreadsoftware.net/global-logsfoldermbs.shtml), or Apple’s one, you can find each domain, (and not only domains, btw) has an ID (like -32764 for the “Network” domain). By passing the folder code to some declares, along with the code for the domain you want, you can get the right folder (e.g. the “Audio” folder of the “local” domain: /Library/Audio, the one of the “system” domain: /System/Library/Audio or the user’s one: /Users//Library/Audio).

Xojo’s SpecialFolder module is nice for common folders, but you may quickly find its limitations.

Great stuff @Arnaud Nicolet thank you very much for that in depth analysis of the issue, very much appreciated especially helpful when I’m pretty ignorant in macOS structure.

You’re welcome; I’m glad you appreciated it.