revoke forbiddance to send Apple events to System Events

I have been using Gitk provided by Git provided by Homebrew with success, for several years.

A couple of days ago, it suddenly prompted a security window when called.

I did not allow access, hoping I would be able to change my mind.

Now trying to start Gitk will always cause:

$ gitk --all
Error in startup script: 58:103: execution error: Not authorised to send Apple events to System Events. (-1743)
    while executing
"exec osascript -e [format {
        tell application "System Events"
            set frontmost of processes whose unix id is %d to true
        end te..."
    invoked from within
"if {[tk windowingsystem] eq "aqua"} {
    exec osascript -e [format {
        tell application "System Events"
            set frontmost of processes ..."
    (file "/usr/local/bin/gitk" line 12237)
$ _

I would need to revoke that forbiddance.

I have removed Git and reinstalled:

$ brew remove --force git && brew install git

That didn't solve the case1. Force was used in order to remove all versions.

If I don't fix this, I'd need to get used to either Tig or Sourcetree or some other alternative, with an impact in immediate productivity.

1: After reinstalling, error is the same, just moved to line 12212. That's because I use taint patches on top of official Gitk. As you can see, those patches are unrelated to the cause, so please don't let it make you focus away from the actual issue, which is 100% macOS materials.


Check setting under: System Preferences > Security & Privacy > Privacy

If you find nothing there, then in Terminal, read the man page for: tccutil

man tccutil

You can use the following command to reset all permissions you've set on AppleEvents:

tccutil reset AppleEvents

Note that after doing so, you'll have to respond to all previous queries that may come forward again.


Note: A few years back there was a project IIRC on GitHub that allowed reading the privacy database and targeting specific occurrences of a set permission, but I think changes in macOS Mojave crippled it. It might be worth doing a bit of googling if you'er looking to target just a specific occurrence of an app permission that is not available in the GUI.


I've hit this issue several times and today I found a solution described @ macobserver by Dave Hamilton, so the credit belongs to Dave.

My setup is:

macOS Mojave, Macport and ohmyzsh, XQuartz

Issue:

As described above, when I run $> gitk, I got same failure (I cannot recall if I was ever been prompted, but this thread makes me believe I could not).

Error in startup script: 58:102: execution error: Not authorised to send Apple events to System Events. (-1743)
    while executing
"exec osascript -e [format {
        tell application "System Events"
            set frontmost of processes whose unix id is %d to true
        end te..."
    invoked from within
"if {[tk windowingsystem] eq "aqua"} {
    exec osascript -e [format {
        tell application "System Events"
            set frontmost of processes ..."
    (file "/opt/local/bin/gitk" line 12261)

The accepted answer from @user3439894 gave me some hope, but I didn't realise until I found Dave's post permissions are divided into groups like Accessibility (the one I was always looking into), and Automation which is where the solution hides.

Fix

  1. Open System Preferences > Security & Privacy > Privacy and there
  2. Select Automation group from the left hand side panel
  3. Spot unchecked Terminal or similar application enter image description here
  4. Check it & close the System Preferences window
  5. Try to run gitk again. Voalà... enter image description here