@UI Move Cursor After SubString

MACRO:   @UI Move Cursor After SubString

--- VER: 1.0    2016-12-23 ---

DOWNLOAD:

@UI Move Cursor After SubString.kmmacros (9.3 KB)


ReleaseNotes

Author.@JMichaelTX

PURPOSE:

  • Move the Cursor to AFTER StringToFind within the Selected String

MACRO SETUP

  1. Set the KM Variable for "SCPT__StringToFind" in the Magenta-colored Action (first Action below)
  2. Move Macro to Group which limits activation to the app(s) you plan to use this macro with.
  3. Assign a Trigger of your choice (default is Status Menu)
  4. You can also trigger using the "Trigger by Name" macro/action.

HOW TO USE:

  1. Select the Main String in your App
  2. Trigger this Macro

TAGS: @Strings @UI @AppleScript

USER SETTINGS:

  • Any Action in magenta color is designed to be changed by end-user
  • This macro uses Google Search and Google Chrome, but can be easily changed

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)+


Macro Image


AppleScript Code
(*
==========================================================
  Get Position of End of Substring within Main String
==========================================================

RETURNS:
  • Position of End of StringToFind within MainString
  • 0 if StringToFind is NOT Found
  
VER:   1.0    LAST UPDATE:   2016-12-23

AUTHOR:    @JMichaelTX

Keyboard Maestro VARIABLES REQUIRED
  • SCPT__MainString -- string to be searched
  • SCPT__StringToFind -- sub-string to find within SCPT__MainString
  
REQUIRED:
  1.  Mac OS X Yosemite 10.10.5+
  2.  Keyboard Maestro 7.3+
==========================================================
*)

tell application "Keyboard Maestro Engine"
  set mainStr to getvariable "SCPT__MainString"
  set subStr to getvariable "SCPT__StringToFind"
end tell

if ((mainStr = "") or (subStr = "")) then
  error "ERROR:" & return & ¬
    "These KM Variables must be set and not empty:" & return & "SCPT__MainString" & return & "SCPT__StringToFind"
end if

### For Testing ###
-- set mainStr to "1234;6789"
-- set subStr to ";"

--- Get Start of StringToFind ---
set posSubStr to offset of subStr in mainStr

if (posSubStr > 0) then
  --- Add Length of StringToFind to Start Position ---
  set posSubStrEnd to posSubStr + (length of subStr) - 1
else
  set posSubStrEnd to 0
end if

return posSubStrEnd
1 Like

For reference, this macro was written in response to this request: