How Would I Get the Line Number of Selected Text in a Variable?

I've revised my macro from the other topic to provide an example of what you are now asking for.

Example Output

image

image

MACRO:   Get Selected URL and Line Number from List [Example]

--- VER: 2.0    2019-08-23 ---
Requires: KM 9+   macOS 10.11 (El Capitan)+
(Macro was written & tested using KM 9.0+ on macOS 10.14.5 (Mojave))

DOWNLOAD Macro File:

Get Selected URL and Line Number from List [Example].kmmacros
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


ReleaseNotes

Author.@JMichaelTX based on script by @ccstone

PURPOSE:

  • Get List of URLs (or MD Links) from Google Search Results
  • Works for FrontMost Browser

HOW TO USE:

  1. Do a Google Search in either Safari, Chrome, or Chrome-based Browser
  2. Trigger this macro

WHAT IT DOES:

  1. Scans the Google results, and returns one link per result
    • Each Line contains LineNumber«Link
  2. User is then prompted to select one line from results
  3. The Line# and Link are displayed

MACRO SETUP:

  1. Review the Actions in magena color, and change as desired
  • Local__Max_Links
  • Local__Return_Data
  1. IF Local__Return_Data is set to "MD", then it returns Markdown links
  • Default: URL
  • Markdown Format: [Link Text](URL)
  1. The max number of links returned is set by the Variable Local__Max_Links
  • Default: 10
  1. ADD the Actions you want to process the results (list of URLs)

TAGS: @XPath @Google @Chrome @Search @Links @JavaScript

USER SETTINGS:
• Any Action in magenta color is designed to be changed by end-user

REF:

ACTION COLOR CODES

• To facilitate the reading, customizing, and maintenance of this macro,
key Actions are colored as follows:
• GREEN -- Key Comments designed to highlight main sections of macro
• MAGENTA -- Actions designed to be customized by user
• YELLOW -- Primary Actions (usually the main purpose of the macro)
• ORANGE -- Actions that permanently destroy Varibles or Clipboards

REQUIRES:

(1) Keyboard Maestro Ver 7.2.1+
(2) Yosemite (10.10.5)+
(3) Safari or Google Chrome


1 Like