How can i run a shell script with administrator privileges within SwiftUI using osascript

前端 未结 1 990
独厮守ぢ
独厮守ぢ 2021-01-23 07:07

I’m trying to make a simple macOS App which runs a shell script with administrator privileges when a specific button is pressed. To run the shell script in term

相关标签:
1条回答
  • 2021-01-23 07:41

    The correct terminal command should be as (if you use specific shell inside script then sh should be replaced correspondingly, say bash)

    $ osascript -e 'do shell script "sh /Users/andreas/checkertool.sh" with administrator privileges'

    so your arguments should be as follow:

    process.arguments = ["-e", "do shell script \"sh /Users/andreas/checkertool.sh\" with administrator privileges"]
    

    P.S. assuming you do this w/o sandbox, because I have doubts it would allow this.

    0 讨论(0)
提交回复
热议问题