Can't allow Automator Service assistive access

I have an Automator service which works in Safari. I created it in Automator as a new service but Automator saves it as a Workflow. The service runs an AppleScript that copies the current URL, switches to another app and pastes the URL into a text box in that app. To paste the URL, the service needs to be allowed Assistive Access (in the Security & Privacy preferences pane).


The problem is that the preference pane doesn't provide for Services to be granted assistive access unless they are applications. The workflow services are greyed out in the open file dialog. But, I can't save my service as an application because that prevents it being recognised by macOS as a service.


I've granted assistive access to Automator but that doesn't seem to provide assistive access for any individual workflows.


Is there a way out of this mess ?

iMac, macOS Sierra (10.12.6), late 2009, Core i5, 2.66Ghz, 12Gb

Posted on Oct 23, 2017 9:57 PM

Reply
2 replies

Oct 24, 2017 5:54 PM in response to HD

The script checks whether an AppleScript applet is running. If not, it launches the applet and calls handler inside. If it is running, the applet is brought to the front and a text field value is set to the URL. So "pastes" is the wrong word - the Service uses GUI Scripting to set the value of a UI element of the target dialog or runs a handler in the target applet. Thus, it is the automator workflow that is doing to GUI scripting not the target applet.


But, workflows "as Services" cannot be granted assistive access so, the GUI scripting part fails.


Since my post, I have succeeded in registering an applet, containing the script, as a Service which is also granted assistive access. I manually edited the info.plist file to add NSService dictionary details so that the applet could be registered as a service. But, that applet has to be manually registered in the Keyboards pref pane before it appears in the Services menu - just putting a copy in the Services folder didn't work. Also, running it inside Safari takes over a minute before the target applet is launched or brought to the front. So, I'm not much advanced.


This is the script which is inside the Automator workflow (and the applet registered as a Service):


set app_name to short name of (info for (path to frontmost application))

if app_name is "Safari" then

using terms from application "Safari"

tell application app_name

set current_URL to URL of current tab of first window

end tell

end using terms from

else if app_name is "Firefox" then

tell application app_name to activate

tell application "System Events"

keystroke "l" using command down

keystroke "c" using command down

end tell

delay 0.5

set current_URL to the clipboard

else if app_name is "Opera" then

tell application app_name

set current_URL to URL of front document as string

end tell

end if

set MacYTDL_appName to "MacYTDL"

set startIt to false

-- Is MacYTDL running

tell application "System Events"

if not (exists process MacYTDL_appName) then

set startIt to true

end if

end tell

-- MacYTDL is not running - launch it and pass the URL to main dialog

if startIt then

tell application MacYTDL_appName

ignoring application responses

launch

called_by_service(current_URL)

end ignoring

end tell

end if

-- MacYTDL is running - bring it to the front...

if startIt is false then

tell application "System Events"

if not frontmost of process MacYTDL_appName then

set frontmost of process MacYTDL_appName to true

set value of text field 1 of window of process MacYTDL_appName to current_URL

end if

end tell

end if



Many thanks,


Garry

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Can't allow Automator Service assistive access

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.