0

I have a simple script that automates the command "Export Library" in Music. It does the following:

tell application "System Events"
    tell process "Music"
        set libmenu to menu item "Library" of menu "File" of menu bar 1
        click menu item "Export Library…" of menu of libmenu
        tell window 1
            click button "Save"
            tell sheet 1 to click button "Replace"
        end tell
    end tell
end tell

(So basically it opens the menu and clicks the obvious buttons, saving me a few clicks). However, after upgrading to Ventura (macOS 13.0), this stopped working. The command click button "Save" is failing with:

Can’t get button \"Save\" of window 1 of process \"Music\"."

I tried to say click button 1 or click button 2 instead, but that doesn't work. I then said name of every button and it printed

{missing value, missing value, missing value}

I couldn't find a good manual for AppleScript, but it does look like something changed in Ventura. Any hints will be appreciated!

Thanks,

Gideon Av
  • 111
  • 1
  • 1
  • 7
  • That is one of the problems with GUI scripting - you need to figure out the new object hierarchy when the UI gets changed. I don’t have Ventura to post an answer, but instead of clicking the button(s), use `get UI elements` and start exploring (viewing the event in the log), adding found elements such as `group`, `splitter group`, etc, to the window tell statement to see what UI elements are in those until you find the desired element. – red_menace Oct 30 '22 at 17:18
  • Thanks, I'll try that . I should note that the UI hasn't changed, it's still exactly the same window with the same button. – Gideon Av Oct 30 '22 at 21:40
  • It depends on how it is built - a UI can look the same but have its elements arranged in a different order, for example controls can be declared in a different order or grouped in a different view. – red_menace Oct 30 '22 at 21:50

2 Answers2

0

OK, I replaced click button "Save" with:

        repeat with b in (get buttons)
            if name of b is "Save" then
                click b
            end if
        end repeat

Interestingly, I can still click the "Replace" button directly without resorting to a loop.

Thanks!

Gideon Av
  • 111
  • 1
  • 1
  • 7
  • PS sorry about the typo in the subject line! Obviously I meant "upgrade to Ventura" – Gideon Av Oct 30 '22 at 22:20
  • Actually this doesn't work, or at least not all the time. I added `log (name of b)` in the loop and it keeps saying "missing value". I wish I knew what to ask instead, but I don't see any docs on how to examine these objects. – Gideon Av Oct 31 '22 at 15:14
0

OK! I found a hint for the answer here: Just add a short delay before trying to click on "Save"!

        delay 0.5
        click button "Save"

Without the delay, the the dialog doesn't seem to be ready and indeed if you do get buttons you will only see the 3 from the top left corner (close, minimize, zoom). With the delay, get buttons returns 6 buttons, including the "Save".

Gideon Av
  • 111
  • 1
  • 1
  • 7