Get number of occurrences found by "Find" (in Safari)

Is there a way to get the number of occurrences reported by the "Find" tool in an app — in my case, right now, Safari?

Hey Kirby,

Sure.

------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2017/04/10 09:29
# dMod: 2017/04/10 09:33 
# Appl: Safari
# Task: Collect the number of matches from the Find field and save to a KM variable.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Safari, @Keyboard_Maestro_Engine, @System_Events, @Collect, @Number, @Matches, @Find, @Field, @Save, @Variable
------------------------------------------------------------------------------

tell application "System Events"
   tell application process "Safari"
      tell (first window whose subrole is "AXStandardWindow")
         tell splitter group 1
            tell tab group 1
               tell group 2
                  tell static text 1
                     if it exists then
                        set foundItems to its value
                     else
                        set foundItems to "missing value"
                     end if
                  end tell
               end tell
            end tell
         end tell
      end tell
   end tell
end tell

tell application "Keyboard Maestro Engine"
   setvariable "safariFindCount" to foundItems
end tell

------------------------------------------------------------------------------

-Chris

3 Likes

UI Browser strikes again? I’ve been using it a lot recently and it makes life so much easier.

1 Like

Chris — Fantastic! Thanks. I will put it to work tonight. :smiley:

1 Like