Save the patcher function inside a standalone

Ullstein's icon

I built a standalone app and would like to include a function that the patcher saves to disc at closebang without having a Mac dialog appear.
The idea is to save a few data in the app each time it is closed without asking the user to save it.
Is there any command available to do so? I checked the complete browser but cannot find any. Is there are workaround to get there?
Thanks!

Andrew Pask's icon

You'll need to save stuff to the standalone's preferences folder.

Cheers

-A

Ullstein's icon

Hi Andrew,
thanks for your quick response, but please forgive my stupidity:
- my app does not have or create a preference folder, or at least I cannot find it. Where would it be? In user/Library/Preferences?
- and how do I save to the preferences? Sorry I've never done that...
- is there any tutorial or so?

Thanks again

Floating Point's icon

this
https://cycling74.com/tutorials/get-your-max-standalone-on-apple%E2%80%99s-mac-app-store
has information re mac but I think you can apply it to windows too

Andrew Pask's icon

You can set a custom name for your app's prefs using the standalone object, in its inspector.

Then you do something like

Max Patch
Copy patch and select New From Clipboard in Max.


to get the path to it, which you can use to save things. In general, users do not have permission to modify apps folders.

Cheers

-A

Ullstein's icon

Thanks Andrew and thanks to Floating Point. That solved my problem, many thanks

Ullstein's icon

Sorry Andrew and Floating Point, but the problem is not solved yet. Yes I can create a folder in "~Library/Application Support", write a .txt-file into it, but I can't read it out, because the separation of the two words "Application" and "Support" makes any "read" command to the "Text"-object assuming additional arguments. When I make a symbol out of the path, it cannot find it. How do I access "Application Support" from within a patch?

Thanks and sorry for bothering so much.

Floating Point's icon

you need to enclose the file path in double quotes, for example:
(read "my mac/Library/Application Support/my text.txt")

you can use the tosymbol object to help with this

Ullstein's icon

Hi Floating Point,
many thanks, in the meantime I found it. I just made to many trials, so that I got confused, I had the solution already, but did not see it, due to over concentration. Sorry for bothering
Many thanks again and have a good day... Hans Peter

Yao anping's icon

Is this method effective for macOS: 15.1.1 (24B91), MAX 9? I tried it and it didn't seem to work.

Source Audio's icon

for most users library folder is invisible.

why not write into documents folder instead ?

you can use unix shortcut to avoid need to detect user name.

write ~/Documents/myfile.json

Yao anping's icon

Thank you for your reply. Like in the attachment?

myfile.maxpat
Max Patch

Source Audio's icon

if you use read or write using

~/Documents/myfile.json

it should read and write the file.

dealing with pattr itself is a different topic.

It is up to you to arrange storing of presets and file so that it does

what you want.

I would not trust closebang in standalone.

Yao anping's icon

If you don't use closebang in standalone then what do you usually do?

Source Audio's icon

Depends on the goal.

Only 100% safe way is to disable usual Quit using

keyboard shortcuts or menu, then add a button

(with a long press to execute)

which first performs what you want,

and after that sends message

;

max quit

Yao anping's icon

Thank you for your sharing and help!

Source Audio's icon

here is example patch

hold quit button > 1000 ms.

if you release button outside of it

it does not execute ....

Max Patch
Copy patch and select New From Clipboard in Max.

handling of standalone will be different if you use Windows.

Yao anping's icon

Wow! The parameters were really saved—such impressive technique. You know, resources on this topic are indeed quite scarce, and it has truly stumped many people. Thank you for your generous sharing—I will study your patch carefully! Thanks again!