I just wanted to see if anyone more experienced with MacOS (primarily develop on Windows) can help me with a small issue I'm currently trying to resolve. Based on the comments I just want to add some quick clarity that this question is in regards to running an executable as admin/sudo in macos NOT without having to run it via command line.
So I have an application that I wrote in golang for some users, and whenever I perform a:
chmod +x ./myGolangApp
sudo ./myGolangApp
The application functions as intended. With this myGolangApp
it pretty much acts as it's own installer plus does a few more things, in which it needs to be ran as sudo/elevated permissions in order to install some services. Again, this all works great simply running the commands I listed above and our users are happy with it.
The problem I'm having is that I would like to be able to distribute this application by creating a .app
package and signing it with my Developer ID and then having the user be able to simply double click the .app
package and having them enter in the credentials so that the install can proceed.
I've tried to create a .app package structure and then creating a Info.plist file to invoke it like:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleName</key>
<string>myApp</string>
<key>CFBundleExecutable</key>
<string>myApp</string>
<key>CFBundleIdentifier</key>
<string>com.company.myApp</string>
<key>CFBundleShortVersionString</key>
<string>8.6.7.9</string>
<key>CFBundleVersion</key>
<string>8.6.7.9</string>
<key>CFBundleIconFile</key>
<string>SetupIcon</string>
<key>LSUIElement</key>
<true/>
<key>NSHumanReadableCopyright</key>
<string>Copyright 2020 XXXXX</string>
</dict>
</plist>
But when I double click on the app, it does absolutely nothing at all. If I try to run the .app from the command like:sudo ./myApp.app
I immediately get: sudo: ./AgentSetup.app: command not found
but if I run sudo ./myApp.app/Contents/MacOS/myGolangApp
, it executes as normal. I'm trying to get around using the command line for this.
I saw some suggestions on apple.stackexchange, one of which got me the closest I suppose in which someone attempted to write a small AppleScript, export it as an application and run something like:
set currentPath to POSIX path of ((path to me as text) & "::")
set installerPath to currentPath & "testscript.app/Content/Resources/Scripts/myGolangApp"
do shell script installerPath with admin privileges
And this.. Kind of works, but this keeps causing my application to throw an exception an exception for some reason, but I can't tell why and to be honest, I don't really like this hacky way of clicking a .app bundle > having it call an applet
executable > which then invokes this script > which then calls the executable to be ran with administrator privileges. This seems like such an unnecessary workaround, and maybe this is partially my ignorance to how OSX - Catalina works.
Is there a way I can simply invoke the .app to call my executable with sudo?
sudo -s
where the script will ask for a password. Here's an example of how to do it: https://apple.stackexchange.com/a/346713/119271 – Allan Feb 08 '20 at 00:20.app
bundle that a user will download. I would like to be able to simply double click it and have the.app
bundle bring up a prompt for admins to be able to log in. Is that possible with the example you linked (or is it possible at all)? Reading through it, it doesn't seem like it. – Chris Feb 08 '20 at 00:28