Does anyone know of a way to connect with these 2 boxes, not using mouse?

I have a number of KM macros that saves me a huge number of mouse clicks.

However sometimes these two boxes "Format Font" and "Format Color" decide to adjust position on my screen so the programmed pixel offsets miss their mark... And of course there are the moments where I decide to change resolution on my iMac27-5k.

My quick fix is to place nonstick clear tape on the screen on the correct positions & circles this with black and then use the "Get" command to adjust.

But is is a nuisance so if I could direct the pointer to these two windows and then direct the click offset, I gather it would me a bit more stable.

I want to select "Black" and the font size box, here shown containing '20'.

GreyT

Skærmbillede 2021-10-24 kl. 20.09.13

Hey Palle,

To do this in a relatively bombproof fashion you'll need to do some AppleScript UI-Scripting.

Something like this for the Fonts Dialog:

--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2021/10/24 17:37
# dMod: 2021/10/24 17:37 
# Appl: System Events
# Task: Change Font Size in System Font Dialog to 20.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @System_Events, @Change, @Font, @Size, @Dialog
--------------------------------------------------------

tell application "System Events"
   
   tell (first application process whose frontmost is true)
      
      tell (first window whose subrole is "AXFloatingWindow" and name is "Fonts")
         
         perform action "AXRaise"
         
         set its position to {475, 112} -- change {X,Y} as necessary.
         set its size to {525, 340} -- change {Width, Height} as necessary.
         
         tell splitter group 1
            tell group 1
               tell text field 1
                  set its value to "20"
                  perform action "AXConfirm"
               end tell
            end tell
         end tell
         
         tell (first button whose subrole is "AXCloseButton")
            perform action "AXPress"
         end tell
         
      end tell
      
   end tell
   
end tell

--------------------------------------------------------

NOTE – this has been tested on Mojave, but it very possibly will not work with later versions of macOS due to under the hood UI changes.

I'll look at the Color dialog later.

-Chris

Thanks for supplying this AppleScript Chris. I have a simple AppleScript I use for the colors window in Apple Notes...but Notes' accessibility features are pretty lacking. For instance, it has no subrole listed, which makes it impossible (as far as I can tell with my limited AppleScript experience anyway) to control it using the subrole.

I imagine this might be the case for GreyT situation too. @Palle_GreyT could you tell us what app you're doing this in?

The subrole has nothing to do with the Notes.app per se – it's a property of the Fonts Window.

My script works perfectly well with Notes on Mojave.

This is why I'm not talking to a specific app but to the FrontMost app:

tell (first application process whose frontmost is true)

I'm attempting to make the script as generic as possible.

-Chris

1 Like

Hi Chris,

Thanks for your effort, but I'll stick to my present solution with tape (pun intended).

I just updated system to Monterey and 'everythin' seems to be fine.

Palle

Haha that's why I like to amend my comments with something along the lines of "I don't actually know what I'm talking about when it comes to AppleScript" :laughing:

-Chris

2 Likes

It seems that the problem is to get the Fonts window to the front. I find that a mouse click relative to a found image can bring the Fonts window to the front. Once it's in the front (add a ~.3 second pause), you can size it as desired and then click anywhere you desire relative to "Front Window". This test step uses an image captured near the upper left corner, including the word "Collection". Make sure to grab the image when the window is NOT in front as that's how it will be when you activate your macro. This test was done in TextEdit, but should work in any Mac app that uses this window.

image

Super Eidco...

I tried it out and it looks like it is a solid solution.
I made a copy of my present macro and changed the action to connect to the Font "window" (which indeed is elusive)
I selected the Image as the text 'Apple' since this will be stable in my setup. (Having success by selecting a color, would depend on if it has the grey background or not)

As it is now it works perfect no matter where my Scrivener window is placed and where the Color may pop up. I include screen-grabs here, and when the macro is trimmed I'll post it into the macro library.

Next thing will be to do the same for the Font window.

Skærmbillede 2021-10-27 kl. 16.40.42

1 Like

I'm glad I could help.

Note that if you change your manner of color selection, the "Apple" image won't be there. It might be better to use an image of the color wheel (above it) as that will be there no matter what the last selection was.

Well for now, it works and is stable.

However my optimism on doing it too for Fonts (Skrifttyper in Danish) came to a test, because I run MacOS in danish version and my app, Scrivener will only show me English version, even it is indeed same system function.

Anyway I found an app where I could get the English "System version" of Fonts and then I made the 2 fonts windows same size (using a ruler) :nerd_face:

After that I could copy the image from the English and adjust the offset from that, once again putting tape on the screen, and voila. It has now worked as desired for some tests.

Just for history I post the screenshot of the Danish(MacOS) and the English (Scrivener) version