How Do I Select an Element of SnippetsLab UI ( click on found pixel action)?

I want to make a macro that would click here :

I can make a macro like this :

But that is very slow. If only there was a fast way to 'click on this pixel' action, in this case pixel's colour being blue.

If you restrict your search to the left edge of the front window (presuming this is the front window), then the search would be a lot faster.

Hey Nikita,

SnippetsLab has fairly poor accessibility, so I can’t actually select the cell itself.

But I can get the frame location of the the cell, and you can use that to make your click action.

It should be pretty fast assuming you only need to get frame of cell number 1.

------------------------------------------------------------------------------
# Get Frame of FIRST Cell.
------------------------------------------------------------------------------
tell application "System Events"
   tell application process "SnippetsLab"
      tell (first window whose subrole is "AXStandardWindow")
         tell splitter group 1 of splitter group 1
            tell table 1 of scroll area 1
               tell row 1
                  tell UI element 1
                     set cellOneFrame to value of attribute "AXFrame"
                     set {x1, y1, x2, y2} to cellOneFrame
                  end tell
               end tell
            end tell
         end tell
      end tell
   end tell
end tell
------------------------------------------------------------------------------

If on the other hand you want to get the frame of the selected cell things slow down according to how many items there are in the list.

------------------------------------------------------------------------------
# Get Frame of SELECTED Cell.
------------------------------------------------------------------------------
tell application "System Events"
   tell application process "SnippetsLab"
      tell (first window whose subrole is "AXStandardWindow")
         tell splitter group 1 of splitter group 1
            tell table 1 of scroll area 1
               tell (first row whose UI element 1's selected is true)
                  set selectedCellFrame to (value of attribute "AXFrame")
                  set {x1, y1, x2, y2} to selectedCellFrame
               end tell
            end tell
         end tell
      end tell
   end tell
end tell
------------------------------------------------------------------------------

Why specifically are you wanting to click something that’s already selected?

-Chris

Hey Chris, since you're already focused on the SnippetsLab UI, can you tell me how to click on a Folder by Name:

I'm working on some KM Macros to automate SL.
Will be glad to share when I'm done.

Hey JM,

Here are some examples.

You have to extract the frame and use Keyboard Maestro as the clicking-agent.

-Chris

------------------------------------------------------------------------------
tell application "System Events"
   tell application process "SnippetsLab"
      tell (first window whose subrole is "AXStandardWindow")
         tell outline 1 of scroll area 1 of splitter group 1
            
            -------------------------------------------------------------------
            
            # Get row names.
            set rowNames to value of static text 1 of UI element 1 of rows
            
            
            -------------------------------------------------------------------				
            # Talk to row by number.
            tell row 5
               tell UI element 1
                  set axFrameOfRow5 to value of attribute "AXFrame"
               end tell
            end tell
            
            -------------------------------------------------------------------
            
            # Talk to row by name.
            
            set rowname to "Perl.pl"
            
            tell (first row whose UI element 1's static text 1's value is rowname)
               tell UI element 1
                  set axFrameOfRow5 to value of attribute "AXFrame"
               end tell
            end tell
            
            -------------------------------------------------------------------
            
         end tell
      end tell
   end tell
end tell
------------------------------------------------------------------------------

Many thanks Chris! This is great! :+1:

Here is a macro that uses your script, with a couple of extra lines:

###MACRO:   Select (Click) Folder in SnippetsLab

~~~ VER: 1.0    2017-02-19 ~~~

####DOWNLOAD:
Select (Click) Folder in SnippetsLab.kmmacros (5.7 KB)


###AppleScript
Heavy lifting by @ccstone. KM interface by @JMichaelTX.

------------------------------------------------------------------------------
tell application "Keyboard Maestro Engine" to set folderName to getvariable "SSL__FolderName"

tell application "System Events"
  tell application process "SnippetsLab"
    tell (first window whose subrole is "AXStandardWindow")
      tell outline 1 of scroll area 1 of splitter group 1
        
        -------------------------------------------------------------------
        
        # Get row names.
        set rowNames to value of static text 1 of UI element 1 of rows
        
        
        -------------------------------------------------------------------        
        # Talk to row by number.
        tell row 5
          tell UI element 1
            set axFrameOfRow5 to value of attribute "AXFrame"
          end tell
        end tell
        
        -------------------------------------------------------------------
        
        # Talk to row by name.
        
        tell (first row whose UI element 1's static text 1's value is folderName)
          tell UI element 1
            set axFrameOfRow5 to value of attribute "AXFrame"
            set {x1, y1, x2, y2} to axFrameOfRow5
          end tell
        end tell
        
        -------------------------------------------------------------------
        
      end tell
    end tell
  end tell
end tell

---   RETURN FOLDER FRAME COORDINATES   ---
-- (as KM Expects it:  left,top,width,height)

set AppleScript's text item delimiters to ","
return {y1, x1, y2 - y1, x2 - x1} as text
------------------------------------------------------------------------------
1 Like