Console app creates folder requiring password

I have a Mac console app that needs to create a folder in SpecialFolder.SharedApplicationData… so something like /Library/Application Support/MyFolder. But that folder requires an Admin password to create the folder. I only need to create the folder the first time the app runs on a given machine.

So I can do this with a shell and “sudo mkdir” but only if the app is not daemonized… If it is daemonized then there is no opportunity to enter the password and the app cannot create the folder.

If it is not daemonized the Admin can enter the password but then the terminal window must remain open or the app quits… something I want to avoid.

Right now my solution is a small app that has to run on the machine once before they run my main Console app that has a UI to enter the password… but I would like to get rid of that.

I could ask the Admin to enter the password as a command line argument when first launching the app but cannot find a way to apply it in the shell command.

Any ideas how to make this work are appreciated.

Thanks

What about launching your app as root?

e.g., in a terminal:

sudo MyWonderfulConsoleApp

Then your app gets launched with administrator rights (the password is asked in the terminal window) and you can create that folder.

[quote=491634:@Arnaud Nicolet]What about launching your app as root?

e.g., in a terminal:

sudo MyWonderfulConsoleApp

Then your app gets launched with administrator rights (the password is asked in the terminal window) and you can create that folder.[/quote]

Thanks… I will look into that idea.

Yes, that seems to work… Now I just need to get the Admin to launch the app using Terminal instead of from the Finder.

My other solution is to check if the required folder exists in the DontDaemonize event… If it does not then return True which then gives the Admin the opportunity to enter the password. The next time they launch the app the folder will exist and the app will daemonize.

I’d guess, if he’s an admin, he knows the Terminal quite a bit… You may also add your app to the PATH environnement variable. That’s one possibility.

Probably a smart idea, indeed. You just have to take care, for the first time, whether you want your non-daemonized app to continue running or not (just relaunch another instance in case you don’t; you may try a shell with “open -n 7path/to/your \app”).