57

After I updated to Mojave, I can no longer use the automator service I've previously been using with the alert below. enter image description here

  • In Security & Privacy, I already checked AppleScript Editor.

Do you see any problem with my code or is this the problem of the newest macOS?

Script

on run {input, parameters}
set pathList to {}
repeat with itemNum from 1 to count of input
    tell application "System Events"
        copy POSIX path of (container of (item itemNum of input)) to end of pathList
    end tell
end repeat
return pathList
end run

enter image description here

enter image description here

Travelholics
  • 868
  • 1
  • 6
  • 9

14 Answers14

46

This is definitely a part of Mojave's new security framework. In terminal try

osascript -e 'tell application "Finder"' -e 'set _b to bounds of window of desktop' -e 'end tell'

and you may receive:

36:42: execution error: Not authorized to send Apple events to Finder. (-1743)

What is supposed to happen on the first execution is the Finder opens a dialog box informing you that terminal is requesting permission to send events to the Finder. If you allow it, then terminal will get added to the Automation page in System Preferences > Security & Privacy > Automation:

enter image description here

There's two issues that I see at the moment:

  • the implementation of requesting permission for the scripting action appears to be bugged; I've run other scripts that request permission to send events to Safari and the Finder doesn't prompt for permission, it just returns an error.
  • streamlined automation requires some type of mechanism to have the permissions granted a priori; an example would be utilizing AppleScript with Ansible and being unable to preload grants

Others have written up more extensive information about this:

Hopefully this gets worked out before Mojave ships as it seriously impacts automation capabilities on macOS.

Joe
  • 2,352
  • 20
  • 38
  • Thanks, Joe. I can see the problem I have more clearly. – Travelholics Aug 16 '18 at 02:44
  • Basic testing leads me to believe that the expected functionality of being prompted for permission to allow AppleScript events is working in 10.14 Beta 8 (18A371a). That still doesn't answer the question as to whether or not AppleScript applications can be preauthorized for automation purposes. – Joe Aug 22 '18 at 19:28
  • 1
    Does not work for me when running through launchd a python script that calls `subprocess.run(['/usr/bin/osascript', my_script_path])`. I don't get the prompt... – Louis M Feb 26 '19 at 09:49
  • 1
    This helped me with the app center app.rpl(); wasn't working, I follow those steps and check terminal on visual studio. – Pxaml May 21 '19 at 14:29
  • @pxaml I was also able to reproduce the behavior for App Center app.Repl() like you described. – user62171 Jun 04 '19 at 15:15
  • Thanks for this detailed explanation! The first command in your answer successfully prompted me to grant permissions to Finder via iTerm2. When attempting to do the same with a different app, however, the prompt does not appear. Thus, said app does not appear under Security & Privacy → Privacy → Automation → iTerm. It's infuriation that it's not possible to manually whitelist certain apps, especially when the prompt to grant permissions refuses to show up. – leifericf Jan 31 '22 at 10:24
30

I faced same error opening gitk.

Error in startup script: execution error: Not authorised to send Apple events to System Events. (-1743)


SOLUTION

Goto Settings -> Security & Privacy -> Privacy -> Automation -> Privacy tab and check the System Events checkbox.

enter image description here

Abdullah
  • 2,015
  • 2
  • 20
  • 29
  • None of the settings changes worked for me. Editing the gitk file and removing the offending `if` block was my solution - the error output says `(file "/usr/local/bin/gitk" line 12261)` so I simply edited that file. gitk is no longer brought to the front when I launch it but otherwise it works fine. – billrichards Dec 11 '19 at 17:27
  • I was trying to launch the ios simulator from expo cli, and it failed with the mentioned error message. This fixed it! – Brad Parks May 04 '20 at 13:53
  • 1
    I just ran into this issue after upgrading to Big Sur (11.0). The scripts in question were known good on Catalina (10.15), but suddenly stopped working with the new OS. I'm wondering if old problems (from Mojave, 10.14) might have been re-introduced with the new OS. @Abdullah fix worked in this case. Thanks Abdullah. – AFK Nov 19 '20 at 15:37
  • Does anyone know how to "force" an app to appear in this GUI, underneath iTerm 2? Only Finder is showing, and when I try to use `osascript` in iTerm 2 targeting other apps (other than Finder), I get the error saying permission is not authorized. The problem is that the app does not show up in this GUI, and the authorization popup does not show up, so it appears to be impossible to grant the authorization required. I'm running macOS Monterey 12.1. – leifericf Jan 31 '22 at 10:27
18

I had a similar error running AppleScript .app applications. I received the following error:

Not authorized to send Apple events to Finder. (-1743)

A workaround is to export (File > Export) or save (File > Save As, holding Option key to show Save As) a new Application from the .scpt or .applescript source code. This generates a new .app application, which in my case ran successfully. The initial launch required approval (as well as some subsequent launches), and the application was added as an entry under Settings -> Security & Privacy -> Privacy -> Automation.

dannyadam
  • 3,950
  • 2
  • 22
  • 19
  • 1
    The accepted solution didn't work for me, but this workaround did. Thanks for posting this! – Tom Loredo Jan 21 '20 at 05:00
  • this workaround worked for me, for a legacy application running on Mojave, that requires an AppleScript to start up – cloudxix Jul 05 '22 at 23:12
16

I have solved the same issue using the below steps. Open Plist and add the below keys in it

<key>NSAppleEventsUsageDescription</key>
<string>Please give access to Export details to Outlook</string>

You will get a confirmation pop up to allow or disallow when your application starts executes the script first time. if you click allow, it will execute the script.

Roshil K
  • 2,583
  • 28
  • 38
  • This solution won't help Automator (as it should already have this key) -- but if your own application requires apple event access then this new key is required (since 10.14) https://developer.apple.com/documentation/bundleresources/information_property_list/nsappleeventsusagedescription – bmiller Jun 13 '19 at 15:26
  • 1
    Worked like a charm. – Jason Elwood Feb 24 '20 at 22:04
  • Solved a related problem for me, trying to set this up for my own application. Note that I had to enable it under Accessibility, not Automation as shown in Abdullah's answer (in Ventura 13.4.1) – Chris McElroy Jul 08 '23 at 16:48
11

Resetting from Terminal like this fixed it for me:

tccutil reset AppleEvents; tccutil reset SystemPolicyAllFiles

TruncatedCoDr
  • 350
  • 3
  • 6
9

Here is what I did that resolved the issue for me. I went to System Preferences > Security & Privacy > Accessibility (Options on left hand side) > (Enter system password) > Click Automator (or your app you want to enable) and TADA it works.

lrosal
  • 91
  • 1
  • 2
  • 2
    This works, but with a little difference: System Preferences > Security & Privacy> Automation > checkmark 'System Events' under the app you want to enable > Enter system password – Ali Nem Dec 10 '18 at 22:55
  • 1
    I will second @AliNem 's comment. I had an Automator workflow that was instructing System Events to make a keystroke in Finder. In System Preferences > Security & Privacy > Accessibility, I had to first enable Automator in Accessibility, then check "System Events" under Finder in Automation, and finally go back and enable Finder in Accessibility. I got a new error each time I tried to run the workflow between each step, until I had made all 3 permissions changes. – zozo Apr 03 '20 at 10:22
5

UPDATE: Updating to the latest Public Beta (as of 4 August 2018) fixed the issue for me. Prior to this, the issue did persist in all public betas of Mojave.


Original reply:

Just wanted to let you know that both myself and another friend are experiencing this exact same problem, with different Automator workflows that use Applescript (different than yours). We have the problem occurring with both manual activation (Finder --> Services --> click item) and with keyboard shortcut activation.

Even stranger, the workflow performs beautifully when testing inside Automator.

I've filed a bug report through the Feedback Assistant, and suggest to anyone else who sees this that you do too! Squeaky wheel and all...

Automator - Permissions error. "The action “Run AppleScript” encountered an error: “Not authorized to send Apple events to System Events.”"

Automator workflow performing well inside Automator

  • Hmm... I understand that you might have had the same problem like mine because all of my services which made via automator don't work with the alert box. I guess I should wait and see.. – Travelholics Jul 14 '18 at 04:28
  • +1 to this issue. I can run the script inside of the Script editor just fine, but as soon as I make it a quick action or an application and try to launch it fails. – Kush Jul 24 '18 at 17:33
  • 1
    Beta 4 you could 'fix' by copy/pasting to a new script & re-saving. Beta 5 this no longer works & the error is back with a vengeance. – Tetsujin Aug 08 '18 at 08:13
3

I had this error in Terminal.app on Catalina with the simple test script of osascript -e 'tell application "Finder" to display notification "some stuff".

I was not getting the pop-up and did not find any helpful options in Settings -> Security & Privacy -> Privacy -> Automation -> Privacy (neither Automation, nor Full Disk Access). I also did not have any luck with tccutil reset AppleEvents; tccutil reset SystemPolicyAllFiles (other than unfortunately losing all my relevant preferences).

For me, the issue was that I was running the command in tmux. Once I detached from tmux, running the same command in Terminal prompted me for the relevant permissions dialog. Once allowed and reattached to my tmux session, I still could not run the command in tmux (but ran in Terminal outside of tmux). At this point I killed my tmux session, launched a new session, and thereafter was able to run this command in tmux in Terminal.

n8henrie
  • 2,737
  • 3
  • 29
  • 45
2

In my case I had to go:

Settings & Privacy > Privacy > Full Disk Access (in the left hand panel) and add Automator

I had also tried adding Automator to Accessibility as other answers suggested (which didn't initially work for me) so perhaps we need to add Automator in both places.

screenshot showing the new Full Disk Access option

happysailingdude
  • 185
  • 1
  • 14
2

if you don't get something like this when trying to run your apple script, and more over you don't see iTerm in your Automation section in Privacy Setting, then the simplest possible way may help: JUST RESTART your Mac ;) disclaimer: another reason for that situation on my side may be user switching.

enter image description here

andilabs
  • 22,159
  • 14
  • 114
  • 151
1

I was still having issues sending keystrokes a few months after Mojave was released. For me, weirdly the fix was to go System Preferences -> Security and Privacy -> Privacy Tab -> Unlock the Lock with your password -> Remove (with the minus button) Automator from the list of Apps in the Accessibility Row. Maybe there was something from running the betas that needed to get deleted before my scripts could send keystrokes again.

Edit: After quitting System Preferences I was getting the alert error again. Re-adding Automator.app to the Accessibility row seems to have fixed this for now.

nteissler
  • 1,513
  • 15
  • 16
1

I received

execution error: Not authorized to send Apple events to Finder. (-1743)" when running a simple smb mount script on Mojave 10.14.6.

Additionally, no apps were able to add security entries to any of the security lists. For example, Microsoft Teams wouldn't display the "wants access to control" dialog boxes for the camera or mic.

This was a standard access user (non-admin). Temporarily elevating this user to an administrator had no impact. No other users were affected. Newly created standard accounts were also unaffected by the problem.

Executing tccutil reset All as the affected user in the Terminal.app displayed a "failed" error.

The fix in this case was to delete the com.apple.TCC folder in the user's Library ~/Library/Application Support/com.apple.TCC and immediately log out.

On login, the folder and contents are rebuilt and normal behaviors are restored.

Anton Menshov
  • 2,266
  • 14
  • 34
  • 55
0

I was trying to insert the current date into the Reminders app with a keystroke. Instead of using the recommended "Settings -> Security & Privacy -> Privacy -> Accessibility -> Automator", I had to add Reminders instead of Automator so that it would allow the keystroke command to be permitted. It is annoying that it only permits the action on the specific app but that seems to be the case.

0

I ran into this problem today using a script I've had for literally a decade that automated rasterizing Illustrator files in Photoshop only to be told it doesn't have permission without a reason to give it. The solutions above don't work because it has nothing to do with System Events in my situation. I then tested and found out I have the same problem in literally every single app on my computer if using osascript. If I tell it in the script to open a file I get a permissions error, but for some absurd reason if I tell it in a script to close an already open file I suddenly get a permissions dialog:

osascript -e "tell application \"Adobe Photoshop 2021\" to close current document saving no"

Thought I'd post it here to help someone else in this exasperating predicament.

dustinwilson
  • 485
  • 4
  • 8