0

Writing an AppleScript to open Image Capture and click the Import All button.

tell application "Image Capture"
    activate
        tell application "System Events"
            tell process "Image Capture"
                click button "Import All" of group 1 of splitter group 1 of window 1
            end tell
        end tell
end tell

Image Capture opens but the script throws an error message saying it couldn't find the button "Import All".

Have followed advice on other threads on how to check the location in Accessibility Inspector and how to translate that to AppleScript instructions.

What's missing?

2 Answers2

1

To get the button and group numbers, you have 2 ways: use the utility aplication provided by Apple in the developper toolkit "Accessibility Inspector" or use small scripts to find the number yourselves.

I prefer using script method. it is a bit longer sometime, but it always works. Just write a script with instruction get UI elements. Here is a small example of such script:

-- return lis of UI elements of active application and paste result in Excel
property tab : ASCII character 9
global T
-- to find last active application
tell application "System Events"
    set frontmostProcess to first process where it is frontmost
    set visible of frontmostProcess to false
    repeat while (frontmostProcess is frontmost)
        delay 0.2
    end repeat
    set secondFrontmost to name of first process where it is frontmost
    set frontmost of frontmostProcess to true
end tell
set ActifProcess to secondFrontmost as text

tell application ActifProcess to activate -- set active the last actived application
delay 1

-- recursive loop to list all elements of active window
tell application "System Events" to tell process ActifProcess to set myWindow to front window
set T to ""
getUI(myWindow, 1)
set the clipboard to T
display dialog "Result is in clipboard. paste in Excel or text document"



on getUI(UIObjet, myLevel) -- get recursively the list of UI elements
    set AppleScript's text item delimiters to {"//"}
    tell application "System Events" to set UIliste to UI elements of UIObjet
    repeat with oneUI in UIliste
        tell application "System Events"
            set UItext to ("Level=" & myLevel & tab & "Name=" & (name of oneUI) & tab & (description of oneUI) & tab & "Class=" & (class of oneUI) as string) & tab & "Title=" & (title of oneUI) as string
            set UItext to (UItext & tab & "Value=" & (value of oneUI) as string) & tab
            try
                set UItext to (UItext & "Position=" & (position of oneUI) as text)
            end try
            set UItext to UItext & return
            try
                set NbSub to count of UI elements of oneUI
            on error
                set NbSub to 0
            end try
            set T to T & return & UItext
        end tell
        if NbSub > 0 then
            getUI(oneUI, myLevel + 1) -- there are other sub UI elements, get them
        end if
    end repeat
end getUI

Copy this script in Script Editor. Make active the window/application you want to get UI elements. Make this script active and run.

The result is sometime not easy to interpret because developper of the application/window you're looking for may not have use UI element clear names or titles which describe what they are. Then you will have to look their relative position in the window.

pbell
  • 2,965
  • 1
  • 16
  • 13
0

The "import all" button is "button 3 of group 2 of splitter group 1 of window 1" for image capture version 6.6. Also, I prefer to use button number, instead of button name to make sure the script works with any language.

tell application "Image Capture"
activate
    tell application "System Events"
        tell process "Image Capture"
            click button 3 of group 2 of group 1 of splitter group 1 of window 1
        end tell
    end tell
end tell

Please note that any next changes done by Apple on Image Capture will impact your script.

pbell
  • 2,965
  • 1
  • 16
  • 13