How Do I Create a Popup Window for Spotlight Search Prompt?

Continuing the discussion from MACRO: Spotlight Search Prompt:

As many of us know, @DanThomas created an incredible macro/system with the SS Prompt (link above). Dan recommended using a KM Display Window to show the results of clicking ln the SS Prompt Help button.

Unfortunately, when you close that window, the focus does NOT return to the SS Prompt window. You have to click on it to set focus to it.

So, I need one or the other:

  1. A method to set focus to SS Prompt after KM Display Window is closed.

  2. Create a HTML/JavaScript Popup Window from the SS Prompt, that I can display my Help text in.

    • I’m assuming that if I close this popup window the focus will return to the main SS Prompt window.

Any ideas, suggestions, and/or sample code?

@peternlewis - Is there a way to set focus to a Custom HTML Prompt window?

With the help of @ccstone, I figured out how to do this:
However, I had to first modify the HTML file for Spotlight Search Prompt.html

In function KMDidShowWindow()

document.getElementById("title").innerText = _spotlightOptions.title;
document.title  = _spotlightOptions.title;  //##JMTX Add

and remove comment for

<title>Filtered PickList</title>

In order for the SS Prompt Window to have a unique title.

Then, in my macro that does the Display Text, run this script after that Action.

set delayTime to 0.1
set maxTime to 600
set notifyTime to 0.2

set htmlWinName to "Get AppleScript Handler Call"
set dtWinName to "Keyboard Maestro - Display Text"

tell application "System Events"
  tell application process "Keyboard Maestro Engine"
    set elapsedTime to 0
    repeat while (window dtWinName exists)
      if ((window htmlWinName exists) is false) then return
      delay delayTime
      set elapsedTime to elapsedTime + delayTime
      if ((delayTime < 0.2) and (elapsedTime > 2)) then set delayTime to (2 * delayTime)
      if (elapsedTime > maxTime) then
        set msgStr to "Max Time of " & maxTime & " sec exceeded waiting for Handler Details to Close"
        set msgTitleStr to "Display Handler Details"
        display notification msgStr with title msgTitleStr sound name "Tink.aiff"
      end if
    end repeat
    tell window htmlWinName to perform action "AXRaise"
  end tell
end tell

So far this is working well, but I’m open to any suggestions for improvement.

1 Like