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?