is Click at broken on Mavericks? - macos

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).

Related

AppleScript Navigate through MacOS 13 (Ventura) system preferences?

One new feature of macOS 13 Ventura is the new layout and design of the system preferences. However, this caused many of my automation scripts to stop working.
Does anyone know how to navigate through the new system preferences? To be precise, what is the equivalent to the following code which is compatible with macOS 13 Ventura?
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.sound"
end tell
The code above worked with old versions fine, but shows
execution error: System Settings got an error: AppleEvent handler
failed. (-10000)
in macOS 13 Ventura
I've encountered the same issue, it seems to be a known issue, and it was also discussed at https://gist.github.com/rmcdongit/f66ff91e0dad78d4d6346a75ded4b751?permalink_comment_id=4286384
What you're looking for is:
do shell script "open x-apple.systempreferences:com.apple.Sound-Settings.extension"
However, manipulating that screen is another pickle.
Does it have to be AppleScript or is bash okay? If bash is an option, you can use the open command. To your specific ask, you can use the following to open Sound preferences:
open x-apple.systempreferences:com.apple.Sound-Settings.extension
More details can be found here: https://www.macosadventures.com/2022/12/05/how-to-open-every-section-of-macos-ventura-system-settings/

Applescript to "tell" Spotify to play isn't working after OSX update to Yosemite

Previously to the Yosemite update, I used this Applescript to control my Spotify.
Everything worked as a charm when I ran /usr/bin/osascript /Users/jdrummond/SpotifyControl.scpt play/pause.
Now that I have updated my OSX to Yosemite, I keep getting this when I run the same command:
/Users/jdrummond/SpotifyControl2.scpt:1217:1222: script error: Expected end of line, etc. but found identifier. (-2741)
So I tried to create a simple Applescript to interact with Spotify:
using terms from application "Spotify"
tell application "Spotify" to play
end using terms from
But I'm also getting an error:
What am I doing wrong and how to interact with Spotify on Yosemite? Anything changed?
This issue was reported to Spotify and will be fixed in the next update to the desktop client (I'm a developer there and can verify that it has been fixed).
Currently, the following simple script is working for me on OS X 10.9.5, Spotify 1.0.3.101.gbfa97dfe
tell application "Spotify"
playpause
end tell
I saved it as an app in other to use with my Microsoft Keyboard, so that the play/pause button launches the simple app that plays/pauses.
Spotify destroyed the ability to use AppleScript very recently with their latest idiotic update. It's not Yosemite, it's Spotify.

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.

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.

Programmatically enable MAC OSX Assistive Technologies?

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

Resources