Search code examples
macosbashapplescriptautomator

Open OSX application command line solution bypassing graphical admin password


I have made an automator application which runs a couple scripts (and does not use any GUI, but it is opening a GUI for admin password because of my use of with administrator privileges). The main script is started using

do shell script (quoted form of myCommand) with administrator privileges

Because of this, when executing the application, a graphical admin password prompt is presented.

I am trying to execute this application automatically after install via bash and am wondering how I would be able to bypass the GUI password prompt; I'm looking for a way to execute the application via bash and run it silently (no GUI, no password prompt).

Because of the with administrator privileges all the common

sudo open -a /Application/appname.app &

sudo osascript -e 'tell app id "com.app.bundleid"' -e activate -e end

even running as root all still bring up the GUI password prompt.

Is there any way to open an application supplying the GUI password prompt via bash for OSX? Or is there a better way I should have executed the main script rather than do shell script (quoted form of myCommand) with administrator privileges?


Solution

  • The way in which I was able to bypass the GUI password prompt and still use with administrator privileges was to recompile the Automator app and supply the user and password in-line:

    on run {input, parameters}
        set myCommand to POSIX path of ((path to me as string) & "Contents:Resources:script_name.sh")
        do shell script (quoted form of myCommand) user name "local-admin" password "local-adminpassword" with administrator privileges
        return input
    end run
    

    This accomplishes running the Applescript as with admin privileges, but without popping up the GUI password prompt. The app then runs silently, as I needed, and runs the script script_name.sh which in turn runs many other scripts and copies over other resource files out of (from myapp.app/Contents/Resources/) into system directories etcetera.

    For the record, I needed it to act this way because I am deploying this app using Munki and wanted it to automatically run silently after install using a postinstall script:

    #!/bin/bash
    open -b "com.company.bundleidformyapp"
    exit 0