Posted by: @johngaver
So bringing our own copy of osascript: Is this file not versioned, doesn't it have dependencies on OS libraries which might be version sensitive (just thinking about how things happen in olden Windows land), and thus wouldn't it be dangerous to bundle it? Apple does have reasonably decent SIP though (unless manually disabled of course), so I suppose based on your answer to the preceding, it might be better to just invoke it rather than to bundle it.
That risk does exist indeed ... though the binary has been signed by Apple, so it may turn out to be OK.
Again: not the correct way to do things, and it feels a little hacky 😉Â
Posted by: @johngaver
Apps being unable to elevate themselves - OK, so how about we elevate some other helper-ish app, which then just reverse invokes its own elevator in now-elevated mode? That might fly, no?
Probably won't fly. What you could do (or maybe this is what you already meant to say): have a binary "A" start and stay invisible (very easy to do with Lazarus), which then calls "B" with elevated rights.
Posted by: @johngaver
Oh wow seriously? What happens if I pass ParamStr(0) instead?
It works, yaaay!
Yeah, it was early in the morning (for me) and I knew it would be something simple to fix the error (as I had mentioned: it failed for me as well, just needed a minor tweak).
A few things on this line that fails:
status := AuthorizationExecuteWithPrivileges(authRef,'/bin/mkdir "/Library/Application Support/Banana"',kAuthorizationFlagDefaults,arguments,pipe);
Â
The "pipe" parameter can be used to catch the exit code or output text of the command you were calling (if I understood things right) - see the ObjC example.
The parameter "arguments" should be (source):
An argv-style vector of strings (array of null-terminated char * pointers ending with a NULL pointer) to send to the tool.
(You do not need to pass the name of the command as the first argument.)
Â
So this is where I should have passed the path, but it was early and I'm a little rusty on the Apple sauce mix here 😉Â
(arguments needs to be a pointer, to an array of zero or more pointers, that each points to a parameter you'd like to pass)
That should do the trick.