0

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:

adriaan
  • 341

1 Answers1

1

Thanks, @gordon-davisson for guiding me in the right direction.

I moved my plist-file to /Library/LaunchDaemons/ and readded my binary to the Accesibility apps in System Preferences:

You need to do this every time your binary changes. I didn't do that before. So for everybody that encounters this issue as well:

  1. Update your own app/binary
  2. Remove it from the Accessibility list
  3. Add it back to the list (via the + or drag and drop)
  4. Unload & load your app again
    • sudo launchctl unload /Library/LaunchDaemons/your.app.plist
    • sudo launchctl load /Library/LaunchDaemons/your.app.plist
adriaan
  • 341