Reputation: 49
I'm making a simple macOS screenshot to clipboard application with swift for a university project and, to perform the screenshots, I'm using the screencapture utility from macOS.
What I have is a function like this one:
func shell(_ command: String) -> String {
let task = Process()
let pipe = Pipe()
task.standardOutput = pipe
task.standardError = pipe
task.launchPath = "/bin/zsh"
task.arguments = ["-c", command]
task.launch()
let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output = String(data: data, encoding: .utf8)!
return output
}
And then I have a button that calls the function:
shell("screencapture -i -c")
The problem is that when the button is clicked, the screen capture utility is indeed called, however my mackbook pro touchbar is activated with the utility UI, which I don't want since there are options that the user is not supposed to have.
So, the question is: how can I disable the touchbar when the shell method is called?
Thank you!
Upvotes: 0
Views: 180
Reputation: 3530
You can get the process ID pid
of the touchbar
using
ps -e | grep "ControlStrip"
Then you can stop it temporarily using the command
kill -STOP pid
Then after that you can reactivate the touch ID using
kill -CONT pid
This technique won't turn off the touchbar
but rather will freeze it (touch won't work). No action can be taken using touchbar
unless it is resumed.
One liner to get process ID of touchbar in terminal:
pid=$(ps -e | grep "ControlStrip" | awk 'NR==1{print $1}');
Upvotes: 1