'Disable touch bar when taking a screen shot in macOS with Swift
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!
Solution 1:[1]
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}');
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
