How do I refer to an object in a window whose Accessibility Inspector description is “<empty description> (group) [NSBox]” in Applescript?

…衆ロ難τιáo~ 提交于 2019-12-13 07:24:19

问题


I am trying to interact with iTunes "Export Library.." dialog.

I tried "set choices to every menu item of menu 1 of pop up button 1 of group 1 of window winName" but it says "group 1" is an invalid index?

Here's the relevant code: (the call parameters are: "iMac-8GB", "iTunes", "iTunes", false"

on handleDir(dir, winName, appName, createIt)
    local foundIt, ndx
    set foundIt to false
    if winName is not "" then
        tell application "System Events" to tell process "iTunes"
            set choices to every menu item of menu 1 of pop up button 1 of group 1 of window winName

回答1:


You want to use the menu "Export Library…" from iTunes :

The first step is to select the relevant menu. In my iTunes version (12.5.5.5) the menu is in "File" menu, sub menu item "Library" and then sub Menu "Export Library…".

The second step is to fill the export file name and set the destination folder. The Mac "Save as…" window has many shortcuts, valid for all applications. Among others, command G allows to define the complete path to save the file. This path must be in Unix format (with "/" and not ":" for sub levels).

The bellow script does the complete Export Library function. The first 2 rows define the name of the file to save and the path where to save it. Adjust them to your needs.

set myTitle to "test" -- name of the exported file
set myPath to "/Users/myuser/Desktop/Test_folder" -- destination folder for export file

tell application "iTunes" to activate -- make iTunes front
tell application "System Events"
tell process "iTunes"
    click menu 3 of menu bar 1 -- open the File menu
    click menu item 12 of menu 3 of menu bar 1 -- select the Library menu item
    delay 0.1
    click menu item 5 of menu 1 of menu item 12 of menu 3 of menu bar 1 -- select the export library… item
    delay 0.1
    keystroke myTitle -- fill the export file name in the save as… dialog
    keystroke "G" using command down -- shortcut to open Go-to folder window
    keystroke myPath
    keystroke return -- to close the go-to window
    delay 0.1
    keystroke return -- to close the export window
end tell -- process iTunes
end tell -- system Events

I added several delays to make sure your Mac has enough time to open or close windows.




回答2:


Using this code, modified to specifically target iTunes':

tell application "System Events"
    tell front window of (first application process whose frontmost is true)
        set uiElems to entire contents
    end tell
end tell

which came from an answer to Use AppleScript to list the names of all UI elements in a window (GUI scripting)

I discovered that a NSBox is referred to as an "outline" by Applescript.



来源:https://stackoverflow.com/questions/42054693/how-do-i-refer-to-an-object-in-a-window-whose-accessibility-inspector-descriptio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!