Authorize UNIX command to control an application

262 views Asked by At

I want to set up an Automator Quick Action that runs the bbdiff command, and passes it the selected files in the Finder.

I created a Quick Action, and set it to receive "files or folders" in "Finder.app".

Then I added the "Run Shell Script" action, and set the shell to "/bin/bash", and to Pass Input "as arguments". The script is:

/usr/local/bin/bbdiff "$1" "$2"

If I run that script manually from Automator or Terminal (replacing the arguments with real filenames) it prompts me to authorize the host program to control BBEdit, and then it works.

But if I run it from the Finder, I get this error:

The action “Run Shell Script” encountered an error: “You must allow bbdiff to send events to the BBEdit application. Use tccutil reset AppleEvents to reset the system's permissions, and try again. bbdiff: error: -1743”

I tried running tccutil reset AppleEvents and running the action again, but it showed the same error.

I also tried adding bbdiff, /bin/bash, and Finder to the Accessibility and Full Disk Access tabs of System Preferences > Privacy, but nothing changed. It looks like you need to add something to the Automation tab, which can't be done manually.

How can I get it to allow a UNIX command like bbdiff to control an application?

UPDATE:

I managed to work around this by using a "Run AppleScript" action, instead of "Run Shell Script", with this script:

on run {input, parameters}
    tell application "BBEdit" to compare (item 1 of input) against (item 2 of input)
    return input
end run

The first time I ran it, I got the prompt to allow Finder to control BBEdit, and then it worked.

But this wouldn't work for other shell scripts, so the question is still open.

1

There are 1 answers

0
Grzegorz On

In my case, I was able to fix it simply by closing the currently opened BBEdit then opening it again. In my case, I was doing a BBEdit update before the error appears.