Open URL or Search Using Google Chrome

MACRO:   [SEARCH] OPEN URL or Search Using Google Chrome

UPDATED: 2019-12-01 21:08 GMT-6

  • Fixed Execute AppleScript that displayed results in a window.

~~~ VER: 2.1.1    2019-12-01 ~~~
Requires: KM 8.2.4+   macOS 10.11 (El Capitan)+
(Macro was written & tested using KM 9.0+ on macOS 10.14.5 (Mojave))

DOWNLOAD Macro File:

[SEARCH] OPEN URL or Search Using Google Chrome.kmmacros
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


ReleaseNotes

Author: @JMichaelTX

PURPOSE:

• Using Selection, or Remainder of Paragraph if No Selection
• IF Web URL, Open the Web Page in Google Chrome
• IF Non-Web URL, Open URL in Default Provider
• IF NOT an URL, Search using Google Search in Chrome

TRIGGER: I suggest ^⇧G

HOW TO USE:

(1) SELECT either: text to search for, or URL to Open
OR
Place cursor at START of text (will be auto-selected from cursor to end of paragraph)
(2) Run this Macro.

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

By downloading or installing this software, you agree to the terms of usage in the below Action labeled "License and Usage Agreement".  
DO NOT INSTALL OR USE IF YOU DO NOT AGREE.

5 Likes

Below is the script required for the last Action:

tell application "Keyboard Maestro Engine"
  
  --- DELETE ALL KM VARIABLES WITH THIS PREFIX ---
  
  set prefixStr to getvariable "KMVarPrefix"
  
  if (prefixStr ≠ "") then
    set value of variables whose name starts with prefixStr to "%Delete%"
    --    display notification "All KM Variables with PREFIX = '" & prefixStr & ¬
    --      "' have been deleted." with title "Keyboard Maestro Script"
  end if
  
  --- DELETE KM VARS IN THE VARIABLE "KMVars_To_Delete" ---
  
  set varsToDeleteList to paragraphs of (getvariable "KMVars_To_Delete")
  
  if (varsToDeleteList ≠ {}) then
    
    set varsToDeleteList to varsToDeleteList & {"KMVars_To_Delete"}
    
    repeat with oVar in varsToDeleteList
      setvariable (oVar as text) to "%Delete%"
    end repeat
    
    ##    display notification "All KM Variables in 'KMVars_To_Delete' have been deleted." with title "Keyboard Maestro Script"
    
  end if
  
end tell

My apologies for failing to provide this as part of the Macro.

1 Like

JMTX - thanks for sharing! simplifies me a few clicks.

In scenario of text it googles, for URLs it opens fine; however I get a AppleScripts Results box which says
"The output of script 'Unknown' is:
Execute AppleScript Exception"

I just click "ok"/ hit enter and continue on, irrespective. no biggie. unsure how to triage or help isolate if it’s a potential problem.
thanks

Have you made any changes to my macro?
I use this many times a day, and I've never seen anything like you describe.

What versions of KM and macOS are you running?
Please provide a screenshot of the "AppleScripts Results box"