Detect User Change of App Name

Mac Desktop:
If you create a compiled app with a given name, say Frog.app, can the application detect that the user has used the Finder to change the name. The purpose would be to allow a user to have multiple instances of the same app differentiated by the user herself.

Say FrogA.app, FrogB.app & FrogC.app.

Each app instance could then have its own ApplicationData folder to store the static data that “characterized” that app instance.

I have created an app that allows the user to highly customize its user interface. The data that stores this customization is in the ApplicationData folder for the application. My problem is trying to figure out in the application itself what name the user has assigned in the Finder to the that instance of the application.

As the developer I could provide say, ten instances of the app, distinguished only by a single constant in the App itself (say “FrogA” in one, “FrogB” in the next etc.) But this seems extremely awkward. And ultimately limits the number of instances a user can access. If there was a way that the app itself could detect any name that the user created, that would solve the problem. The user would create as many copies of the app as they wished and then give them each a different name and the application could “use” that name.

Technically yes.

You can read the name of the application bundle, to which you could manually create a fake bundle identifier “com.yourURL.frogA”. From this “fake” bundle identifier, you could then create a NSUserDefaults instance, that reads and writes the preferences for this instance (any preferences the system stores on your behalf would still go to the original preferences). You’d have to maintain an application support folder yourself.

You would however run into problems with the  App Store as you’re not allowed to color outside of the lines. You’d end up having to maintain preferences and settings in a subfolder of the application support folder. You may also run into other issues in regards to the  App Store DRM.

Here’s a example of the code (in bold) I use when I need the finder application name (application_filename)


dim application_filename, application_name as string

application_name = App.ExecutableFile.Name

application_filename = Replace(app.ExecutableFile.NativePath.NthField("/",app.ExecutableFile.NativePath.CountFields("/")-3), “.app”,"")

if application_filename <> application_name then
MessageBox("’"+application_name+"’ has been modified to ‘"+application_filename+"’")
end if


I hope it helps

1 Like

Remarkable. It works for me.

One little thing: there are curly quotes rather than straight quotes around .app which I had to change

It should have been straight quotes. It was pasted with straight quotes but I didn’t saw that they’ve been changed in curly quotes by the integrated text editor used by the forum.

If you paste it into a code block, it won’t change the quotes.

1 Like

But does it have to change the quotes otherwise? :thinking:

Might be the OS doing it. On Macs there is a system preference setting to automatically replace straight quotes with curly ones - so if you have that set then …

2 Likes