r/applescript • u/flamboyant-dipshit • Nov 04 '22
Not sure AppleScript is the right tool: Cycle through windows of game who have same window name
Greetings.
I have a simple AS that activates a EVE Online window, the first it finds with a simple
tell application "EVE" to activateThat works great and from there my AS abilities start to fail me. I'm hoping to cycling through possibly multiple EVE windows (each a separate launch of the app), but I don't know what I'm doing.
I can get the "id" of each process, but that just gives me a list of pids and I'm not sure how to activate one of those...even just the first and then I'll figure out how to cycle later.
tell application "System Events"
set pID to the id of (every process whose name contains "EVE")
end tellWhich in my case returns 208947,385118,667811, but "activate 208947" or "activate id 208947" doesn't work.
I then went in search of app/window ID (not pid as it seems "activate" wants a winID, not a pid...but IDK), but I cannot construct a proper "set" to get there. I tried:
set winID to the id of (window of process whose name contains "EVE")That returns "{{{}, {}, {}}, {{}, {}, {}}}" which doesn't look very useful.
Anyways, I'm lost and I'm pretty sure I may have gone to the "stream of consciousness" level now, I hope it makes sense and doesn't make me look like a raving lunatic.
2
u/AmplifiedText Nov 04 '22
The
id of (window of process...stuff might be failing because macOS is very strict about access to that information anymore. If you're writing and running this script in Script Editor.app, you may need to grant Script Editor "Screen Recording" permission in System Preferences > Security & Privacy > Privacy tab.It's also possible/likely that EVE Online windows do not implement Accessibility, which is the API used to present information about windows via System Events. Without Accessibility support, those windows are basically "empty" (no information, can't be manipulated).
1
u/stephancasas Nov 05 '22
Window IDs are not available to System Events — only to the application. You'd need to retrieve the windows using a tell block for the application itself.
If you want to accomplish the same thing with System Events, you can get the windows, but they'll be by name. I don't know the AS for it, but here's the JXA:
1
u/[deleted] Nov 05 '22
[removed] — view removed comment