I am trying to work around an issue with a palette that doesn't have definable UI elements (InDesign 2024 Check Spelling dialog). Additionally, I want to avoid using the "Find Image on Screen" functionality for various reasons based on our workflow.
What I’m looking for is the ability to trigger an AppleScript that opens a Pashua dialog, then, after a two-second delay, sends the Pashua dialog to the background, so InDesign then becomes the frontmost app.
Here’s the use case: An operator runs an AppleScript in Adobe InDesign, which eventually brings up the "Check Spelling" dialog. At that point, I want a Pashua dialog to appear with a message like, "Return to this dialog after you finish spell check." The Pashua dialog would contain two buttons: "Abort AppleScript" and "Continue with AppleScript." After the operator clicks "Done" in InDesign's "Check Spelling" dialog, the script would return to the Pashua dialog and choose one of the buttons to proceed.
Does anyone know if this is possible with Pashua and Applescript?
I didn't even know what Pashua was, but I see it's "a tool for creating native dialog windows on macOS"[1].
Keyboard Maestro has an Execute AppleScript action which you could put in your macro, but you want to trigger the macro from a click on InDesign's palette..?
Perhaps you could do that by setting your macro to trigger from a mouse click using This USB device key, but then you would have to test where the click was made. If image detection isn't desirable, you could perhaps put something together using the MOUSEX and MOUSEY functions, but that would depend on the palette always being in the same part of the screen, which seems unlikely!
Unfortunately, the palette will always be in different locations.
Maybe Keyboard Maestro could provide the ability to do the following:
I already have a macro that executes an AppleScript for InDesign, which triggers InDesign's spell check at a certain point.
At that moment, could the AppleScript activate a Keyboard Maestro macro that runs in the background in a repeat loop until another trigger is executed? For example, after the operator closes InDesign's Check Spelling dialog, they would press a trigger (such as Cmd-Opt-1) to stop the macro from looping and return a variable to the AppleScript, signaling it to continue executing the rest of the script.
You could just include your "Pause" in the AppleScript. Limited testing, but something based on this might do it:
tell application "Adobe InDesign 2024" to activate
delay 1
tell application "System Events"
tell process "Adobe InDesign 2024"
repeat
if (every UI element whose subrole is "AXFloatingWindow") is {} then
exit repeat
else
delay 0.1
end if
end repeat
display dialog "Done Spellchecking"
end tell
end tell
Paste the above into Script Editor. Make sure InDesign has the Spellcheck dialog up. Run the above script, which should run and run until you get bored and close the Spellcheck dialog, at which time it will pop the dialog.
Demoed like this because the dialog is only "visible" to System Events when InDesign is the frontmost app -- so you'll have to make sure of that in your workflow.
Limited knowledge of InDesign, so I don't know if there are potentially other "AXFloatingWindow"s you'll have to make sure are closed first (panels that you've moved out of the layout area aren't counted, thank goodness!).
Hello Nige_S,
I appreciate your response. What you're suggesting is what I had implemented in previous versions of InDesign. However, in InDesign 2024, the Check Spelling window is no longer recognized as a unique UI element.
Like I said, I don't use InDesign enough to know if there are other "floating windows". If you can give some examples perhaps we can find a way round them.
Technically, there are no other conflicting items. The issue arises from a few remote machines failing to recognize a section of the top sliver of the Check Spelling dialog window when using a repeat loop in conjunction with "Find Image on Screen." For most machines, this macro works fine. When the top portion of the Check Spelling dialog can no longer be found on screen, the repeat loop stops, and the AppleScript continues. However, since the problematic machines are remote, I cannot adequately troubleshoot the issue with "Find Image on Screen," despite all System Preferences being correctly set (e.g., granting Keyboard Maestro Engine access to record the screen).
As a result, I was looking for a solution—manual or otherwise—that would trigger the AppleScript to continue after the Check Spelling dialog is closed. I was able to successfully implement this solution using the suggestions from Kevinb in this thread.
At this point, I am completely satisfied with the current process.
The AppleScript above works as a "pause while the spellcheck window is open" on my machine (KM image detection is not involved). If it doesn't for you then it would help to know in what way it doesn't work. Does it not pause? Does it not unpause?
Because, on my machine at least, it is recognised as a "unique UI element" -- at least, when InDesign is the frontmost app. So it may be that InD is losing focus and it just needs the condition to include that state too. Or, if it doesn't unpause, you've got another floating window open -- it may be possible to trap for, and discount, that but you'd need to check its properties to see there's anything you can use.
Thank you Nige_S,
I will investigate some more and reply with my findings. Unfortunately, unfortunately, I am out of pocket (no computer access) for a few days.
Btw, you are using Indd 2024, and System Events recognizes the palette?
Yes, the script above works -- perhaps because it isn't a "palette", but it can be found by getting every UI element whose subrole is "AXFloatingWindow".
Nige_S, I really owe you one. What you've done works flawlessly and is absolutely fantastic! Thank you so much for your patience and for putting up with my stupidity, responding multiple times to help me out!