Work Faster in Windows With Launchy and a few Python Scripts

2007 December 4
by Arun Bhai

Eating the Mouse

Launchy is a great productivity tool and a cool way to impress your friends. You can launch any application by pressing a hotkey (say Alt+Space) and the first few letters of the application for eg: typing ‘gi’ will display the GIMP icon and pressing Enter will launch GIMP. You can download Launchy from its website and its beta is pretty stable (and gorgeous) on my XP laptop too.

Using Launchy gets pretty addictive and soon you will hate using the Start menu or even Explorer on Windows for opening applications or files. So I took the red pill and started automating the following things with a little help from Python:

  • Launching Intranet applications inside Internet Explorer (even if Firefox is your default browser)
  • Bringing minimized or overlapped windows to the foreground

Some Necessary Evil

Don’t get me wrong, I hate IE as much as you do. But the fact of life is that many web apps out there “Work best when viewed in IE” (TM). Even if you have launchy plugins to launch the web app, if your default browser is Firefox, it might show incorrectly. Here is the solution:

  1. Install Python and Pywin32
  2. Copy the following script to the Utilities directory (it will be in the path where you installed Launchy) and save it with a .pyw extension not a .py extension

Python:

from win32com.client import Dispatch
ie = Dispatch("InternetExplorer.Application")
ie.Visible = True
ie.Navigate(r"http://intranetapp/home")

In the above code replace the URL http://intranetapp/home with the URL of your choice.

Finally, open Launchy, right-click and say ‘Rebuild Index’.

No more Alt-Tabbing around

If you are like me, you’ll have a lot of windows open at the same time. I have tried increasing the task bar height and grouping similar windows feature in XP to manage them. But I always wish I could invoke commonly used open applications like my chat window in just a few keystrokes. Launchy doesn’t index open programs by default, but with some python magic I can show you how to bring some commonly used windows to the foreground:

  1. As before, install Python and Pywin32
  2. Copy the following script to the Utilities directory (it will be in the path where you installed Launchy) and save it with a .pyw extension not a .py extension

Python:

import sys
from win32gui import GetWindowText, EnumWindows, ShowWindow, SetForegroundWindow
from win32con import SW_RESTORE, SW_SHOW

TITLE_MATCH = "Microsoft Excel - Expenses.xls"

def listWindowsHandles():
    res = []
    def callback(hwnd, arg):
        res.append(hwnd)
    EnumWindows(callback, 0)
    return res

def listWindowsNamesAndHnd():
    return [(hwnd, GetWindowText(hwnd)) for hwnd in listWindowsHandles()]

def unminimizeWindow(a_hwnd):
    ShowWindow(a_hwnd, SW_RESTORE)
    SetForegroundWindow(a_hwnd)

def finder1():
    for hwnd, title in listWindowsNamesAndHnd():
        if TITLE_MATCH in title:
            unminimizeWindow(hwnd)

finder1()

In the above code change the string Microsoft Excel – Expenses.xls with the title the window you would like to summon.

Finally, open Launchy, right-click and say ‘Rebuild Index’.

This works even if the window was minimized.

I hope, finally you can throw your mouse away. Ah… What a bliss!

Distantly Related posts:

  1. Making Python Scripts Show Windows-friendly Errors/Stacktrace
  2. Windows+Python Integration Like Unix shell
  3. Emacs Tip: A Key to open the Current Folder in Windows
  4. Is Python Intellisense Possible in Emacs?
  5. 5 Indispensable Tips for Emacs on Windows
14 Responses leave one →
  1. December 4, 2007

    Wouldn’t it just be simpler to execute “iexplore.exe http://intranetapp/home” instead of writing a python program to make COM calls?

  2. December 4, 2007

    @Siddharta: Atleast for me, iexplore.exe is not in the path of a batch script running in my system. I might have to change the PATH variable for that.

    The advantage of this method is it is independent of the path where the user installed the program

  3. December 4, 2007

    I don’t think i click as much as the average Win user does.

    I use ALTAP Salamander (it’s got a speed dial to configure your most used paths) as a file browser and usually hit Microsoft-M to reach the desktop and from there type the name of the app i want to launch and hit Enter.

    If i want to launch Firefox i Microsoft-M, type “moz” and click Enter.

    You need to sort your own icon names so that they don’t clash with each other.

  4. Steve permalink
    December 4, 2007

    iexplore.exe isn’t on the path, but you can still use it with the Run prompt. Hit Win R, type “iexplore google.com” and hit enter, it launches IE with the specified website. Works great.

    I tried Launchy but I find it didn’t buy me much. I’ve always used a combination of the windows command prompt (it’s not useless!) and Win R and rarely use the mouse (at least for launching a program).

  5. Togakangaroo permalink
    December 4, 2007

    Also great for using when you have an lmhosts file set up. For example, I have my test IP address mapped to the word test, and productions servers to prod1, prod2, …

    Bringing them up is a matter of typing int test int prod1 … (int = internet explorer)

    And in general great for passing parameters too sqlplus username:password@host …

  6. December 4, 2007

    I use launchy AutoHotKey. Launchy to as a program launcher..and Autohotkey for global shortkeys and macros for various tasks. You might find it much easier and more suitable rather than dropping to python.

    Much of the functionality is built-in,for which you would need extensive coding in python.

  7. David permalink
    December 4, 2007

    Firefox has a plugin (IETab) that can open specific pages/domains in IE embedded in tab. Very elegant, and even easier than the above :-)

  8. December 4, 2007

    @Steve: I’m a great fan of Win R combination. Since it works out-of-the-box on any windows box, I tend to use it all the time. Unfortunately, some of my commonly used URLs are too cryptic to type, esp the ones on my intranet. Hence the need to use such automation tools.

    @David: I agree IETab is a good solution for the first scenario. But somehow, I always end up too lazy to install it :)

  9. December 4, 2007

    better to just use a real os, methinks

    but for those unfortunate souls who have no choice/haven’t quite come around, this isn’t bad

  10. December 10, 2007

    Yek.! I think I should try tht.. Was using the winR till now.!

    • Pss.. I’m lazy writing scripts.!
  11. March 6, 2009

    What do you type in Launchy to get to your Excel window after you create the Python script?

  12. March 8, 2009

    @pf:

    You can type the first few letters of the filename of the python script to bring the Excel sheet to front. for eg: to open “My Expenses.pyw” just type “My Exp” or shorter.

    The more often you use, the lesser number of characters you will have to type because Launchy learns as you use it.

  13. LReebz permalink
    July 15, 2009

    Thanks!! Extremely useful! And this idea can be extended to any number of other useful tasks which Python scripts can accomplish.

    Note: it may be necessary to add “*.pyw” to Launchy’s list of File Types for the Utilities folder in order to run these scripts.

Trackbacks and Pingbacks

  1. Caminews » Work Faster in Windows With Launchy and a few Python Scripts at ArunRocks

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS

Additional comments powered by BackType