« Enable access for assistive devices » on MAC OSX 10.11 El Capitan for GUI scripting

applescript1

I’ve been looking for a way to improve dialog boxes in my Applescript scripting.

I found that GUI could be a way to do that (Graphic User Interface).
Going to that web page presenting the GUI scripting, I learned that I must first

« Enable access for assistive devices »

By searching the web on how to do that on OSX El Capitan, I stumbled upon that page that explains some ways.

Then I designed a script to help you do so. It is as follow (copy/paste in script editor),
(or open it directly in Script Editor by clicking here)

GUIScripting_status()

on run {}
GUIScripting_status()
end run

on GUIScripting_status()
(* This script is based on ‘https://macosxautomation.com/applescript/uiscripting/index.html’ script
and was improved by David Tribal for davidtribal.com *)

— check to see if assistive devices is enabled
tell application « System Events »
set UI_enabled to UI elements enabled
end tell

— If GUI is not enabled
if UI_enabled is false then
set OSX_10_8 to « 10.8 ou avant »
set OSX_10_9 to « à partir de 10.9 »
set annuler to « Annuler »

set t_OSX_10_8 to « This script utilizes the built-in Graphic User Interface Scripting architecture of Mac OS x which is currently disabled. » & return & return & « You can activate GUI Scripting by selecting the checkbox \ »Enable access for assistive devices\ » in the Universal Access preference pane. »
set t_OSX_10_9 to « This script utilizes the built-in Graphic User Interface Scripting architecture of Mac OS x which is currently disabled. » & return & return & « You can activate GUI Scripting by allowing the applications you use for Applescript (as Automator or Script Editor) to controle your computer in the preference pane »

set answer to the button returned of (display dialog (« Quelle est ta version de Mac OS X ? ») buttons {annuler, OSX_10_8, OSX_10_9} default button 3 with icon caution)
if answer is annuler then
return
else if answer is OSX_10_8 then
set systempane to « com.apple.preference.universalaccess »
set TheText to t_OSX_10_8
else if answer is OSX_10_9 then
set systempane to « com.apple.preference.security »
set TheText to t_OSX_10_9
end if
tell application « System Preferences »
activate
set current pane to pane id systempane
display dialog TheText with icon 1 buttons {« Ok »} default button 1
end tell
else if UI_enabled is true then
display dialog « GUI is alreayd Enabled my friend ;) » with icon 1 buttons {« Ok »} default button 1
end if
end GUIScripting_status

—–

Thanks to Eric Meyer’s URL Decoder/Encoder for the URL encoding tool

Qu’est-ce qu’une URL ? – sur Comment ça marche

 

Related posts

Pour commenter sans FB c'est ici ? (laissez votre contact si vous le souhaitez)