21.4 C
New York
Thursday, September 19, 2024

The means for Applescript to entry the PDF menu button from the Chrome Print window modified in Sonoma


So, because of @benwiggy, I discovered that the UI modified in Sonoma. So I spent a while attempting to determine how to determine what factor the PDF button is in Sonoma.

I discovered this reply on stackexchange to be helpful:

How one can enumerate the UI components in applescript

You can even use UIBrowser3, which is extra handy than the AppleScript methodology.

I found that the PDF button is now:

menu button 1 of group 2 of splitter group 1 of window "Print"

Which results in the revised (and dealing) code:

    inform utility "System Occasions"
        inform course of "Chrome"
            set frontmost to true
            delay 1
            
            # Open the print dialog
            keystroke "p" utilizing {command down, possibility down}
            
            
            
            # Wait till the Print dialog opens earlier than continuing
            set repeatcount to 0
            repeat till exists window "Print"
                set repeatcount to repeatcount + 1
                if repeatcount > 50 then
                    show dialog "Print window not detected"
                finish if
            finish repeat
            
            key code 48 # ship tab character to go to first web page
            key code 48 # ship tab character to go to final web page
            keystroke "1" # make web page 1 final web page
            key code 48 # tab to scale field
            keystroke "90" # set scale to 90    
            #set UIElems to UI components of group 2 of splitter group 1 of window "Print"
            #show dialog UIElems
            # Develop the "PDF" menu button (have to be expanded earlier than the menu is referencable)
            click on menu button 1 of group 2 of splitter group 1 of window "Print"
            
            # Wait till the Menu button menu is created earlier than continuing
            #delay 2
            repeat till exists menu merchandise "Save as PDF…" of menu 1 of group 2 of splitter group 1 of window "Print"
            finish repeat
            # Choose the "Save as PDF" menu merchandise
            click on menu merchandise "Save as PDF…" of menu 1 of group 2 of splitter group 1 of window "Print"
            
            # Wait till the Save dialog opens earlier than continuing
            repeat till exists button "Save" of sheet 1 of window "Print"
            finish repeat
            
            # Paste the filename in  and Save
            
            set worth of textual content subject 1 of sheet 1 of window "Print" to SaveFileName
            
            click on button "Save" of sheet 1 of window "Print"
            

As @benwiggy factors out, this can be lower than optimum, as a result of the logical construction of the consumer interface components can change at any time (as proven by Sonoma), however it’s helpful for my utility and for infrequent scripting.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles