0

I am trying to get all rows from a table of the application.

set ProcName to "AppName"
tell application ProcName to activate
tell application "System Events"
    tell process ProcName
        tell tab group 1 of window 1
            set items to every row of table 1 of scroll area 1
            set itemValues to {}
            repeat with aRow in items
                set itemValue to (value of text field 1 of aRow)
                log itemValue
                set the end of itemValues to itemValue
            end repeat
        end tell

    end tell
end tell

However when I run the script it prints out only several items because the window title is constantly changing and I get the following error.

 "System Events got an error: Can’t get window \"App name window title"

Is it possible to tell the script to use other identifiers other than title? Or please suggest how to solve the issue.

Thank you.

  • Your snippet isn't using a window title, it is using an index - is there more to this script? – red_menace Sep 15 at 16:21
  • @red_menace, but it fails with the error – solderingiron Sep 15 at 17:00
  • When using indexes, the error should be something like "Can't get window 1", so I am nor sure where the actual title of a window is being used or even accessed. Also, I noticed that you are using items as a variable name - that is a reserved word AppleScript uses for reference forms, so you need to change it to something else. – red_menace Sep 15 at 18:21
1

The simplest way is using the Application's bundle identifier. This can be found from reading the Info.plist file within the application package, or with some simple AppleScript such as:

get id of application "TextEdit"

This returns com.apple.TextEdit.

Then, one could run the following AppleScript:

tell application id "com.apple.TextEdit"
    activate
end tell

So, your revised could would look like this (note use of process id since you're using System Events).

-- set bundleId to id of application "AppName"
set bundleId to "com.apple.TextEdit"

tell application id bundleId to activate
tell application "System Events"
    repeat with theProcessId in (processes whose bundle identifier is bundleId)
        tell process id (id of theProcessId)
            tell tab group 1 of window 1
                set items to every row of table 1 of scroll area 1
                set itemValues to {}
                repeat with aRow in items
                    set itemValue to (value of text field 1 of aRow)
                    log itemValue
                    set the end of itemValues to itemValue
                end repeat
            end tell
        end tell
    end repeat
end tell
  • Thanks for the answer, however I get an error ""System Events got an error: Can’t get process \"com...." – solderingiron Sep 15 at 16:09
  • You need to replace com.xyz.AppName with the actual bundle id of your process. See my note above. I commented out the line where you could gather this dynamically (though I don't recommend it, esp. if this is causing the problem in the first place) – dxdc Sep 15 at 17:53
  • This was done, but I still get the error – solderingiron Sep 15 at 17:57
  • I've posted a new variant for you @solderingiron... let me know if it works differently. – dxdc Sep 15 at 21:53
0

The first thing I personally would do would be to add some delay commands. Then run the code with the delay commands. Sometimes that makes a difference.

set ProcName to "AppName"
tell application ProcName to activate

repeat until application ProcName is frontmost
    delay 0.2
end repeat
delay 0.1

tell application "System Events"
    tell process ProcName
        repeat until exists of tab group 1 of window 1
            delay 0.1
        end repeat
        tell tab group 1 of window 1
            set items to every row of table 1 of scroll area 1
            set itemValues to {}
            repeat with aRow in items
                set itemValue to (value of text field 1 of aRow)
                delay 0.1
                log itemValue
                delay 0.1
                set the end of itemValues to itemValue
            end repeat
        end tell
    end tell
end tell
  • Thanks for the answer, however I am still getting the same error. It can print several items if title stays the same, but when the title changes it throws the error – solderingiron Sep 16 at 15:50
  • What's the application you are trying to use the code on? – wch1zpink Sep 16 at 17:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .