h1

AutoHotKey – Portable Drive Menu

21/02/2009

I’m a big fan of portable applications and particularly the work driven by PortableApps.com.  The PortableApps Menu has been undergoing a revamp for some time now to work towards a number of enhancements and in the mean time I’ve taken up using a branch of this known as Geek Menu.  Unfortunately they are all quite slow as I have a huge number of portable applications on my portable hard drive.

I usually have a small number of applications I use regularly and so I actually want a fast loading light menu for automatic loading and then I load Geek Menu from that should I need access to lots of applications or ones that I use infrequently.

I’ve created a basic little application menu using AutoHotKey that is driven from a simple INI file menu system (that you manually edit) to fill this need.  When run it sits in the system tray and when you click on it it displays a set of menu items (including sub menus) and executes the item associated with it using the path for it in the INI file.

The script for this is as follows:

; Copyright flagit.wordpress.com 2009
;;;;;;;;;;;;;
;MAIN SCRIPT;
;;;;;;;;;;;;;

;;;;;;;;;;;;
;Initialise;
;;;;;;;;;;;;
#Persistent
#SingleInstance

AppName = PUMAS
AppIni = %A_ScriptDir%pumas.ini
IconFile = %A_ScriptDir%pumas.ico

;;;;;;;;;;;;
;Build Menu;
;;;;;;;;;;;;
;Set-up Base Menu Settings
menu, tray, Icon, %IconFile%
menu, tray, tip, %AppName%
menu, tray, nostandard
menu, tray, add, %AppName%, Heading
menu, tray, Default, %AppName%
menu, tray, disable, %AppName%
menu, tray, click, 1
menu, tray, add ; separator

;Build the base menu
BuildMenu("Tray", AppIni)

;Exit app entry
menu, tray, add ; separator
menu, tray, add, Exit, ExitApplication
return

;;;;;;;;;;;
;FUNCTIONS;
;;;;;;;;;;;

;Recursive function to build the menu
BuildMenu(MenuSection, INIFile)
{
    ;Build menus from INI file
    Counter=1
    Loop
    {
        IniRead, MenuEntry, %INIFile%, %MenuSection%, Item%Counter%, *
        If (MenuEntry="*")
            Break
        IniRead, MenuEntryPath, %INIFile%, %MenuSection%, %MenuEntry%, *
        If (MenuEntryPath="*")
        {
            BuildMenu(MenuEntry, INIFile)
            menu, %MenuSection%, add, %MenuEntry%, :%MenuEntry%
        }
        Else
        {
            menu, %MenuSection%, add, %MenuEntry%, ExecuteItem
        }
        Counter += 1
    }
}

;;;;;;;;;;;;;;;;;
;MENU PROCESSING;
;;;;;;;;;;;;;;;;;

;The heading is disabled and simply allows the left click to produce
;the right click context menu
Heading:
menu, tray, show
return

;Open the specified path for the menu item generated from the INI file
ExecuteItem:
;Open the item specified for this in the ini file
IniRead, MenuEntryPath, %AppIni%, %A_ThisMenu%, %A_ThisMenuItem%
SplitPath, A_ScriptDir, , , , , ScriptDrive
Run, %ScriptDrive%%MenuEntryPath%
return

;Close the application
ExitApplication:
ExitApp

There are a few variables in the initialise section that specify the name of the application, the INI file that defines the menu (which is convenient to store in the same folder as the menu script/executable and the icon file for the application.

The INI file has a “Tray” section which defines the root content of the tray item’s context menu.  Each item is specified by “Item#” in numeric order.  Each item specified will either have an entry in the same section (making it an item for execution) or a section of the same name (indicating it is a sub-menu).

An example menu might look something like:


[Tray]
Item1=Utilities
Item2=Tools
Item3=Help

Help=Helppumas.chm

[Utilities]
Item1=Defrag
Item2=Format Floppy

Defrag=File HelpersUnfrag.exe
Format Floppy=batchformatFD.bat

[Tools]
Item1=Tools Guide
Item2=Mega Kit

Tools Guide=ToolsGuide.doc
Mega Kit=Toolsmegakit.exe

This produces a menu system with two sub menus (one for utilities and one for tools) each with two items and a help item on the root menu.  This configuration file specifies all paths in relation to the root of the drive it is stored on.  You can tailor this INI file to your needs and even the menu system itself by modifying the script to what you want – just recompile it with the AutoHotKey compilation tool and you’ve got it.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: