How can I have a shell command run when a user clicks a Button in my Cocoa GUI?
I would like to have a button that when pressed, runs the command caffeinate to keep the computer awake.
I do not know how to code this function and have googled.
How can I have a shell command run when a user clicks a Button in my Cocoa GUI?
I would like to have a button that when pressed, runs the command caffeinate to keep the computer awake.
I do not know how to code this function and have googled.
You run command line commands via NSTask
. You create an NSTask, set the path to the command you want to run, set up the arguments and then call the task. If you google how to use NSTask
I'm sure you'll find some example code.
Here is the Apple Developer documentation for NSTask
: https://developer.apple.com/documentation/foundation/nstask?language=occ