Running on: MacOS Catalina 10.15.5
I made a Quick Action in Automator and it works just fine. In fact, I've been using it for a few years. The code in the action itself is not the problem, nor is it allowing accessibility/controls in system preferences. My problem is mind-boggling to say the least and I cannot seem to figure it out and thought I'd ask the hive mind.
After making my quick action with AppleScript and making sure the 'workflow receives: no input in any application' as I normal would do, then going in and assigning the shortcut the key 'F13' in System Preferences --> Keyboard --> Shortcuts --> Services, everything seems just great.
In the application I use this shortcut in, if I hover over the application main dropdown and hover over "Services" the item is there and has a shortcut 'F13' associated with it. If I select the shortcut from the dropdown menu, it works PERFECTLY.
Here is the problem, if I hit 'F13' on my keyboard, the service runs 3 times in a row. It's almost as if the system services thinks I want to run that particular item 3x. I have tried a number of different shortcut keys as well (as simple as: F13 and as complicated as: ⌘⌥⌃⇧N) and the shortcut keys did not yield any positive results either.
I have checked everywhere and cannot seem to find why this is happening. Any insight/help would be much appreciated. This is not an AppleScripting issue. It's something with the OS that is causing a triple selection on the services menu item for some reason. It does not seem to be a Key Repeater issue either.
Thanks in advance!
The problem, as best as I can tell, isn't that the workflow is running three times, but that you're getting a series of three security error messages. It seems that when you try to run a service using a keyboard shortcut, the system invokes an xpc service (com.automator.runner.xpc, which is located inside the automator application package), and that service is triggering security alerts because it doesn't have the accessibility rights that are needed for GUI scripting. There is no obvious way to grant the xpc the proper rights (and I suspect that would be an enormous security hole anyway), so that's not workable.
However, there's a workaround. Take your functioning script, copy it into a new Script Editor window, and save it as an application using the 'File Format' pulldown at the lower left of the save window:
Give this application permission to use accessibility features:
Now create a service in automator that uses the
Launch Application
action to launch the script application you just created. Assign your keyboard shortcut to that service, and things should work as you like.Of course, this launches an application, showing it in the Dock and grabbing the foreground momentarily, which can be visually distracting. If you want it to run silently in the background, do the following:
Right-click on the icon for the script app and choose
Show Package Contents
.Drill down two levels to find the
info.plist
file, and open it in TextEdit, BBEdit or some other plain-text editorAdd the following key/value pair to the file (being carful not to break up other key/value groups):
Save the info.plist file, then run the app again; it should be faceless.