Windows 7に乗り換えたらコマンドライン・ランチャーは不要になりました

bluewindからCraftLaunchへの移行 を行ったばかりですが、OSをWindows XPからWindows 7に乗り換えたらコマンドライン・ランチャーは不要になりました。
Windows 7のスタートメニューにある「プログラムとファイルの検索」を使うと、bluewindCraftLaunchのようにコマンドラインでアプリケーションを起動することができます。
しかし、そのままでは秀丸を起動するのに「秀丸」と入力しなければいけないので、非効率です。インクリメンタルサーチが使えても漢字で入力するのでは意味がありません。

そこで、CraftLaunchの設定ファイルをWindowsのショートカットに変換するスクリプトを作成しました。これで秀丸Windowsキー + 「Hidemaru」の途中まで入力すれば起動できます。

Python for Windows Extensions を初めて使ってみたのですが、PythonからWSHが使えるのは便利ですね。

#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# usage: craftLaunch2Shortcut.py
#
# インストール要件 :
#
# Python for Windows Extensions
# http://starship.python.net/crew/mhammond/win32/
#
# 参考 :
#
# WshShortcut オブジェクト
# http://msdn.microsoft.com/ja-jp/library/cc364438.aspx
#
# ShellExecute 関数
# http://msdn.microsoft.com/ja-jp/library/cc422072.aspx
#
# ShowWindow Function (Windows)
# http://msdn.microsoft.com/en-us/library/ms633548(v=vs.85).aspx

import os
import os.path
import re
import win32com.client

shell = win32com.client.Dispatch('WScript.Shell')

launcher_dir = os.path.join(shell.SpecialFolders("StartMenu"),
    "Programs", "QuickLaunch")

if os.path.isdir(launcher_dir) != True:
    os.mkdir(launcher_dir)

config_file = os.path.join(os.environ['APPDATA'], "CraftLaunch", "config.py")

for line in open(config_file, 'r'):
    m = re.match(r"        \( u\"(.*)\", *window\.command_ShellExecute\( " \
        "None, u\"(.*)\", u\"(.*)\", u\"(.*)\", (.*) \) \), # (.*)",
        unicode(line, "utf-8"))
    if m != None:
        path_name = m.group(1).encode('cp932')
        target_path = m.group(2).encode('cp932')
        parameter = m.group(3).replace("\\\"", "\"").encode('cp932')
        working_directory = m.group(4).encode('cp932')
        showstate = m.group(5).encode('cp932')
        if showstate == "3":
            # SW_SHOWMAXIMIZED
            showstate = "3"
        elif showstate == "2" or showstate == "7":
            # SW_SHOWMINIMIZED or SW_SHOWMINNOACTIVE -> SW_SHOWMINNOACTIVE
            showstate = "7"
        else:
            # SW_SHOWMINIMIZED
            showstate = "1"
        description = m.group(6).encode('cp932')

        print path_name + '\t' + target_path + '\t' + parameter + '\t' \
            + working_directory + '\t' + showstate + '\t' + description

        shortcut = shell.CreateShortCut(os.path.join(launcher_dir,
            path_name + ".lnk"))
        shortcut.Targetpath = target_path
        shortcut.Arguments = parameter
        shortcut.WindowStyle = showstate
        shortcut.Description = description
        shortcut.WorkingDirectory = working_directory
        shortcut.save()