For people who do not use Windows, stop reading now!

OK, you have been warned. I am a long time fan of SlickRun as I am the type of person that does not like taking his hands off the keyboard. I use it to launch programs quickly by typing a hot-key to bring up a floating window, and then entering a keyword (or first part of). For example, the following screen-shot shows that when I type in fi, it gets completed to firefox automatically.

Recently, it occurred to me that I would like to have the firefox keyword perform the following steps:

  1. If Mozilla Firefox is already running, just bring it to the front; ELSE
  2. Launch the program.

With this behaviour I am then able to use the same action to bring up Firefox regardless of whether it is running. Previously I would have to see if Firefox is already running and then switching to it, or alternatively launching it.

I decided to write a small AutoHotkey script to support this.

    ;; Script for running a process. It will first see if the required window
    ;; is running and if so, bring to the foreground. Otherwise will run the
    ;; specified command.
    ;;
    ;; Arguments:
    ;;   arg 1 - regexp for Window title
    ;;   arg 2 - path to process to execute

    ;; Check for arguments
    if 0 < 2
    {
        MsgBox Need to pass in Window Title and Executable to run
        ExitApp
    }

    SetTitleMatchMode, RegEx
    IfWinExist, %1%
    {
        WinActivate
    }
    else
    {
        Run, %2%
    }

I then used the AutoHotkey compiler to create a standalone executable. I could then use the following command-line to either activate the running instance of Firefox or launch it if it is not already running.

    prompt% O:\myhome\bin\activate-or-run.exe ^
                ".* - Mozilla Firefox$" ^
                O:\FirefoxPortable\FirefoxPortable.exe

The arguments are:

  1. ".\* - Mozilla Firefox$" - regular expression to match on the title of the Mozilla Firefox Window.
  2. O:\\FirefoxPortable\\FirefoxPortable.exe - the command to launch firefox no matching window title was found.

Here is how this is configured as a SlickRun keyword:

I wish I had thought of this technique back when I started using SlickRun. Note that this was just an example using Mozilla Firefox. I use the same technique to access a number of common programs like this and this.

Finally, I know about the Windows 7 Taskbar Shortcuts where Win+number (1-9) starts the application pinned to the taskbar in that position, or switches to that program. This is what inspired the idea, I just find using keywords easier, and I use PortableApps which do not pin nicely to the taskbar.