Saving preference files in the application package (Mac)

Apr 24, 2012 at 8:41pm

Saving preference files in the application package (Mac)

On the Mac, with Max 5, can a Max application save it’s preference files in the .app package, so that the user doesn’t see them in the Finder?

I mean the content you see when you right-click the application: “Show Package Content”

If yes, which file path do I have to use?

#63199
Apr 25, 2012 at 2:24pm

To save preferences, I use a pattrstorage with its file saved into the .app’s Contents/Resources folder. And no file path at all.
Something like this:

– Pasted Max Patch, click to expand. –
#227988
Apr 26, 2012 at 1:20am

How do you save without a file path? Your patch in Max or as compiled version (.app), on close I get asked to save the preference file. I cannot save without a path.

In my application I save on demand by sending “writexml settings.xml” (without path information) to [pattrstorage]. The file gets written to the current folder. In the .app the same happens, the file does not go to the Content/Resources/ folder.

I see a file path parameter in the patcher inspector but cannot delete it to make “no path”. It’s a locked field.

#227989
Apr 26, 2012 at 5:29am

I first save the pref in Max, to create a xml file. Then I move it into the standalone in /Resources by hand. Once the right file is in the search path, it will be replaced with writeagain.

#227990
Apr 26, 2012 at 8:03am

Thanks, I think the ‘writeagain’ was the clue.

However, I tried about 30 times and it worked just once and never again. Even my Max got crazy. It started to write .json files with the ‘writexml’ message, it put my file to the Max folder, always I got write errors in the .app – but it worked once, so I know it can work. Somehow, some time, hopefully, again ;-)

#227991
Apr 28, 2012 at 1:16am

Got it, finally.

Could not manage ‘writeagain’ but found the way to use absolute paths. If someone is interested, below is a patch that reports the current path, be it a Max patch (saved as file) or an application. Works in Max 5 and 6.

Description:

If the message “; max getruntime …” sends 0, you send “path” to [thispatcher]. If the message sends 1, you are in runtime mode and execute “; max sendapppath …” to get the current path. Quite simple.

– Pasted Max Patch, click to expand. –
#227992

You must be logged in to reply to this topic.