Keyboard Maestro “Youtube Search” Macro

I have been using this macro for years, even when I used QuicKeys but it is a bit slow and takes about 3 seconds to open the window on a Mac Pro. Not sure what makes it so slow to open the search box.

Keyboard Maestro “QK - Youtube Search” Macro

QK - Youtube Search.kmmacros (2.2 KB)

I don't see any reason to use a script for this.
This macro runs very fast (< 1 sec):

BTW, it is best to URL encode your query search term.

1 Like

Hey @skillet

Tell me was probably giving it fits...

Try this

-Chris

------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2017/03/28 00:30
# dMod: 2017/03/28 00:39
# Appl: Google Chrome
# Task: YouTube Search with Google Chrome
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Google_Chrome, @YouTube, @Search
------------------------------------------------------------------------------

set frontApp to path to frontmost application as text

tell application frontApp
   set mySearchStr to text returned of (display dialog "Enter YouTube Video Search" default answer "" buttons {"Cancel", "Search"} default button "Search")
end tell

set mySearchURL to "http://www.youtube.com/results?search_query=" & mySearchStr

tell application "Google Chrome"
   
   activate
   
   if (count of (get windows)) = 0 then make new window
   
   tell front window
      
      set activeTabURL to URL of active tab
      
      if activeTabURL = "chrome://newtab/" then -- new tab URL might need tweaking for your setup.
         
         set URL of active tab to mySearchURL
         
      else
         
         make new tab at end of tabs with properties {URL:mySearchURL}
         
      end if
      
   end tell
   
end tell

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

Keyboard Maestro “QK - Youtube Search” Macro

QK - Youtube Search.kmmacros (7.2 KB)

Thank you Michael and Chris, very helpful to see both and see how they compare and to do the same things both ways. The native Keyboard Maestro macro seems a few milliseconds shorter probably just because of the fade for the dialog is not there. Nice to be able to save the AppleScript as an application though.

Hey @skillet,

Why? (Seriously.)

AppleScript applets are generally not more useful than compile scripts or compiled script bundles (with some exceptions).

Exceptions:

  • There might be a reason for keeping one open and running.
  • An applet can be used for drag and drop.
  • Applets can run some AppleScriptObjC that other run methods won't.

If you save any AppleScript as a compiled script and run it as such it will run noticeably faster from Keyboard Maestro.

-Chris

Because I can double click on it and run it without having to use another application to launch or run it. Just nice to have something like that sometimes that I can stick in my dock for temporary use. I know how to get back into it and edit if I need to which is helpful. AppleScripts like this that I use all the time live in Keyboard Maestro as an AppleScript and don't run as an app. Thanks for the help and post.

Hey @skillet,

Okay – that makes perfect sense. I've done it on occasion myself.

-Chris