I'm writing a little Go program that uses osascript (based on mac2mqtt):
func getCommandOutput(name string, arg ...string) string {
var outbuf, errbuf strings.Builder // or bytes.Buffer
cmd := exec.Command(name, arg...)
cmd.Stdout = &outbuf
cmd.Stderr = &errbuf
err := cmd.Run();
stdout := outbuf.String()
stderr := errbuf.String()
if err != nil {
log.Println(stderr)
log.Fatal(stderr)
}
return strings.TrimSuffix(stdout, "\n")
}
func main() {
runCommand("/usr/bin/osascript", "-e", "tell application \"zoom.us\"", "-e", "tell application \"System Events\"", "-e", "keystroke \"a\" using {shift down, command down}", "-e", "end tell", "-e", "end tell")
}
After compiling this code into a file called mac2mqttzoom
I get an executable. I run chmod +x mac2mqttzoom
, run it from Visual Studio Code, and get this dialog:
I hit OK and all is good. Then I create a LaunchAgent file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.adriaan.mac2mqttzoom</string>
<key>Program</key>
<string>/Users/adriaan/mac2mqtt/mac2mqttzoom</string>
<key>WorkingDirectory</key>
<string>/Users/adriaan/mac2mqtt/</string>
<key>StandardOutPath</key>
<string>/Users/adriaan/mac2mqtt/standard.log</string>
<key>StandardErrorPath</key>
<string>/Users/adriaan/mac2mqtt/error.log</string>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
</dict>
</plist>
But when I run this program I get this error:
System Events got an error: osascript is not allowed assistive access. (-25211)
Only when running with Launch Daemons and Agents.
I gave permission via Acccessibility to all relevant apps: