Programmatically enable MAC OSX Assistive Technologies? - macos

IS it possible to enable MAC OS X assistive technologies programmatically on Snow Leopard, Lion and Mountain Lion?
I've got a client with an application that needs the "Enable access for assistive device" checkbox checked in Universal Access. This is for an application that is expected to run on Snow Leopard, Lion and Mountain Lion.
Can it be done via an Applescript or a shell script embedded in an Objective C application or MUST it be enabled manually, explicitly by the user?

Here's what I use...
enable_GUI_scripting()
on enable_GUI_scripting()
try
if (system attribute "sysv") < 4138 then display dialog "This script requires the installation of Mac OS X 10.3 or higher." buttons {"Cancel"} default button 1 with icon 2
tell application "System Events" to if not UI elements enabled then
tell me
activate
display dialog "This script requires the built-in Graphic User Interface Scripting architecture of Mac OS X, which is currently disabled." & return & return & "Enable GUI Scripting now? (You may be asked to enter your password.)" buttons {"Cancel", "Enable"} default button 2 with icon 2
end tell
set UI elements enabled to true
if not UI elements enabled then error number -128
end if
return "yes"
on error
return "no"
end try
end enable_GUI_scripting

Try this :
tell application "System Events"
activate
set UI elements enabled to true
end tell

Related

Simple AppleScript to enable one macOS Mail account, disable another?

I have used a simple AppleScript that toggles between active and inactive macOS Mail accounts that has worked peachy up until macOS 10.15 Catalina. I generally trigger this through the Script Menu to hide one account and enable another, but have also tried by simply opening and running it. Either way, it's now failing with the error:
Blockquote error "Mail got an error: AppleEvent handler failed." number -10000
Here's the script: what am I missing here to having this work in Catalina?
tell application "Mail"
set enabled of account "Mac" to false
set enabled of account "Windows" to true
end tell

applescript and application process name on OSX 10.10

I have an application that I'm running on OSX, and I have this AppleScript that was working on 10.9, but it seems that it does not work on 10.10
try
tell application \"System Events\" to set processPath to application file of application process "My Application"
return POSIX path of processPath
on error errMsg
return ""
end try
When I run this in the AppleScript editor, it gives me the error that "System events got an error: Can't get application process "My Application".
I checked the Activity Monitor, and indeed, there is no process called "My Application" in there. The associated process with my application is now registered by the name "SWT". I confirmed this by killing the "SWT" process, and it killed my app.
My question is, what has changed from 10.9 to 10.10, and why is my application registered as SWT process, instead of "My Application", as it was in 10.9? Additionally, what changes do I need to make in order to register the process by the name of "My Application" (something which I presume will work)?
Update: I tried setting the Application name to "My Application", which worked, and now I am able to see a process called "My Application" in the Activity Monitor, but the AppleScript is still not working. The error that I'm getting now is:
Can’t make alias \"Macintosh HD:Library:Java:JavaVirtualMachines:jdk1.7.0_71.jdk:Contents:Home:bin:java\" of application \"System Events\" into the expected type
Any thoughts on this?
I might have misunderstood your question but if you just want to change your app name from SWT to your application name try this
Display.setAppName("My app name");
This should be set before any display class is initialized.

is Click at broken on Mavericks?

On earlier versions of OS X an applescript like :
tell application "System Events" to tell process "Google Chrome"
get position of window 1
click at {598, 260}
end tell
worked.
But it doesn't work anymore on Mavericks. Is it some kind of broken ?
PS: AppleScript Editor has access to the Accessibility.
Yes, it is. There's some discussion on Apple's site.
Yes. When I try to run
tell application "System Events" to click at {500, 500}
it works in a 10.8 VM but results in an error like System Events got an error: Can’t make {500, 500} into type list in 10.9.
You can use MouseTools instead:
do shell script "MouseTools -x 500 -y 500;MouseTools -leftClick"
This issue has been fixed on Yosemite (tested on Beta 5 and GM).

Xamarin.Mac app that is not visible in Dock

I have a Xamarin.Mac C# application that needs to run as a hidden daemon.
How do I tell my app to not show it's icon in the OS X dock?
Thanks!
EV
You can edit the Info.plist file in your project, create a new property on the Source tab of "Application is agent (UIElement)", and set it to the string of "1".
This is the same as manually setting LSUIElement to 1 in a text editor and tells OS X to launch the application as an agent.

AppleScript - System Events Error : Access for assistive devices is disabled

I have a problem with AppleScript and System Events.
I have check "Enable access for assistive devices" in the “Universal Access” preference pane in System Preferences.
When I try :
arch -i386 osascript -e 'tell application "System Events" to get the position of every window of every process'
I have this error :
System Events got an error: Access for assistive devices is disabled. (-25211)
Do you have any idea ?
Thanks a lot
On Mac OS X 10.9 you actually get the same error when the AppleScript Editor is not allowed to use Accessibility.
Here's how you enable it:
Go to System Preferences > Security & Privacy > Privacy > Accessibility.
Then, just check the checkbox left to the AppleScript Editor and the error should be gone.
The problem is not the assistive devices. AppleScript seems to incorrectly return that error code when it tries to access windows of a process that can never have any windows (in my case it was "Google Chrome Helper").
You need to catch the errors. This works for me:
tell application "System Events"
set procs to processes
set windowPositions to {}
repeat with proc in procs
try
if exists (window 1 of proc) then
repeat with w in windows of proc
copy w's position to the end of windowPositions
end repeat
end if
end try -- ignore errors
end repeat
end tell
return windowPositions
returning a list of coordinate pairs, such as {{1067, 22}, {31, 466}, {27, 56}, {63, 22}, {987, 22}} – is that what you were trying to get?
Similar to the post on this page about Mac OS X 10.9 (Mavericks), to resolve this issue on Mac OS X 10.8 (and likely on earlier versions of OS X also), you need to ensure that the "Enable access for assistive devices" option has been enabled in the Accessibility pane of System Preferences.

Resources