Applications vs Applicazioni

I have a program that when first run tries to detect whether it has been properly placed in the Applications folder. I have an Italian user that gets a message that it has not been placed in the correct folder and wonders if it has to do with the Italian version of MacOS calling the Applications folder the Applicazioni folder.

The code that I use to determine if the application is in the correct folder (the Applications folder is as follows.

Var applicationFolderPath As String = SpecialFolder.Applications.NativePath
Var fiFolderOfRAAViewer As New FolderItem("") // should be the folder that contains the RAAViewer application
Var raaviewerPath As String = fiFolderOfRAAViewer.NativePath
Var matchTrueFalse As String
Var correctLocation As Boolean
correctLocation = FileTools.rfTwoFolderItemEqual(SpecialFolder.Applications, fiFolderOfRAAViewer)

FileTools.rfTwoFolderItemEqual is just a method that compares the NativePath of two FolderItems and concludes that if the NativePath is the same than the folder(s) they refer to are the same.

Const METHOD_NAME As String = "rfTwoFolderItemEqual"
// MODULE_NAME: FileTools
// PARAMETERS: folder1 As FolderItem, folder2 As FolderItem
// RETURN TYPE: Boolean
// DATE/TIME: 2023 § 04/14/23 16:59 - Bearboat Software. 230414_1659
// DESCRIPTION: Insist that both exist. And they both refer to the same FolderItem

If folder1 = Nil Or folder2 = Nil Then Return False // neither can be nil
If Not (folder1.Exists) Or Not (folder2.Exists) Then Return False // neither can not exist
If folder1.NativePath = folder2.NativePath Then Return True Else Return False

The logic is that wherever the user might have placed the application, FolderItem(“”) should return the parent folder of where he happened to place the application. And it should have a NativePath.

Meanwhile we know that if he placed it correctly this NativePath should be the same as the NativePath of the Applications Folder.

Questions:

  1. Is this code logically faulty?
  2. Is there a better way to make this determination?
  3. Is there some reason why the difference in English and Italian spelling of “Applications” is causing a problem? I would assume on an Italian machine that the NativePath of SpecialFolder.Applications would be – /Applicazioni and if you correctly placed the app in this special folder the NativePath of the FolderItem(“”) would also be – /Applicazioni

I am unsure of what you’re doing, but here’s what I feel:

Use SpecialFolder.Applications.Child("Tour.App.Name)
as a way to detect if it is in the Applications folder.

Why ?
Because SpecialFolder.Applications points to the correct folder while other ways (NativePath) certainly returns what the user see (in that case the italian translation.

We have the same name (Applications) in French, so I cannot test.

But, for Library, we have Bibliothèque instead. But, for programming, I will use SpecialFolder.Library and it works.

A little bit shorter:

Var fiFolderOfRAAViewer As FolderItem = App.ExecutableFile // get folderItem of App
fiFolderOfRAAViewer = fiFolderOfRAAViewer.Parent.Parent.Parent.Parent // go up four steps to folder (macOS only)

If fiFolderOfRAAViewer <> SpecialFolder.Applications Then
  // not in the /Applications folder
  Break
Else
  // in the /Applications folder
  Break
End If

According to a number of posters in such as StackOverflow and Apple Discussions, Finder (or, more generally, the GUI) shows the localised name for applications and folders, but at the Terminal level you will see the English names. So I would assume that therefore NativePath will not vary between locales.

1 Like

I would try something like this:

dim appBundle as FolderItem

appBundle=new FolderItem("")

dim applicationFolder as FolderItem

applicationFolder=SpecialFolder.Applications

if not(SpecialFolder.Applications.NativePath=appBundle.Parent.NativePath) then

'app is not in the correct location

end

This has the advantage of avoiding using the name of the app to find its location. Note that it probably only works on the Mac due to the reliance on the bundle path - other platforms should be tested.

I am perhaps misunderstanding this. I cannot see how my solution or others suggested uses the name of the app itself. They are getting references to the Parent folder of the app.

And also the name of the app itself is not being translated into Italian.

I was a little nervous about directly comparing two FolderItems with <> or = which is why I added the extra step of getting the NativePath. But if your code works, one would assume that going through the NativePath would also work.

The code below as is returns the application name.

Dim f as New FolderItem("")
System.DebugLog f.Name

// You can complete with:
If System.Applications.Child(f.Name).Exists Then
// The application is in the Applications folder (whatever will be its local name).
Else
// Issue an error message; this is up to you
End

I forgot .Exists !

Your instincts are correct here. Comparing two FolderItems like that doesn’t do what you’re looking for - it tests to see if the two are the same FolderItem object in memory, not whether the two objects refer to the same item on disk. You’ll need to compare their NativePaths.

1 Like

Sorry for the confusion. Another post made that suggestion, not you.

This code will return true (incorrectly, for the purposes of this discussion) if there is some other item with the same name as the application in the Applications folder - for example, an older version of the app.

My solution guarantees to test that the currently running app is the one in the Applications folder.

1 Like

There are Application.MinorVersion and Application.MinorVersion.

OP will choose.

Not asked by the OP, but good addition.

Make sure that SpecialFolder.Applications is giving you the path that you want. On my machine, that returns /Applications but the user could put the app in another legal location. You’d be better off using declares for this on macOS. for instance, here’s a list of all of the legal places for a user to put an application on a typical machine:

/Users/username/Applications
/Users/username/Applications/Utilities
/Users/username/Developer/Applications
/Users/username/Applications/Demos
/Applications
/Applications/Utilities
/Developer/Applications
/Applications/Demos
/Network/Applications
/Network/Applications/Utilities
/Network/Developer/Applications
/Network/Applications/Demos

Here’s a sample project with the declares you’d need for macOS:
specialfolders_macos.xojo_binary_project.zip (5.3 KB)

3 Likes