Use a shell script in swift (Xcode)

Hey,
I don't know anything about swift but only about shell. That is why I ask here.

My plan is to make an Application where you push a button to activate this script:
Code Block shell
sudo pmset -b sleep 0; sudo pmset -b disablesleep 1

I know, very simple.
But how I can I make this? Thank you.

Answered by DTS Engineer in 658040022
I think you’d be better off using AppleScript for this. AppleScript has three advantages here:
  • It’s very easy to save an applet with a single function.

  • It’s very easy to invoke shell scripts via the do shell script command.

  • That command also supports trivial privilege escalation.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
You will find a lot of references about this question. Such as:
https://stackoverflow.com/questions/58227977/how-can-i-execute-a-shell-script-in-swift

I advise also to read this:
https://developer.apple.com/forums/thread/90111

Hope that helps.
Accepted Answer
I think you’d be better off using AppleScript for this. AppleScript has three advantages here:
  • It’s very easy to save an applet with a single function.

  • It’s very easy to invoke shell scripts via the do shell script command.

  • That command also supports trivial privilege escalation.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
Thank you. That helps me a lot!

Good day and stay health.

tip: you should use echo "password" | sudo -S xxxxx or you'll bu stuck in sandbox

Use a shell script in swift (Xcode)
 
 
Q