I don’t like Windows links (.lnk). They are useful to create shortcuts to other places in the filesystem, but they lack meat. You can’t do much else with them. And the way I use them with Launchy, all I want to do is put them somewhere that Launchy can find them and give them a catchy name I’ll remember so I can just ‘Alt-Space’ and type the link name to rocket to a place in my filesystem.
I have found a better way to use batch files with Launchy, and here is a tutorial on how you can do it, too.
The Scenario
Here is a scenario to better illustrate this example. I have a java project with source folders that I need to navigate to quickly. There is one trunk, and possible branches that I want to have at my fingertips. I not only want to be able to pop up a windows explorer at these locations, but I also need to be able to open a command line so I can run ant tasks. Here is the location of the application (called ‘myApp’) source code. One is a trunk and one is a release branch.
The Environment
Since I’m going to be working on this application for a long time, I might as well set up some environment variables to make the whole process easier. That way if I ever decide to move the location of myApp, I can just change it in one place on the OS and be happy. To quickly open up the ‘System Properties’ window, press the Windows Key (icon here) and ‘Break’ simultaneously (or Right-Click on ‘My Computer’ and choose ‘Properties’). From here, click the ‘Advanced’ tab, then the ‘Environment Variables’ button.
I created three environment variables:
| Name |
Value |
| MYAPP |
C:\dev\java\myApp |
| MYAPP_TRUNK |
%MYAPP%\trunk |
| MYAPP_RELEASE |
%MYAPP%\branch |
The “%MYAPP%” is Windows’ way of using an existing environment variable within another’s definition. This way if I move ‘myApp’ into another location on the filesystem, I just have to change the MYAPP variable and the MYAPP_TRUNK and MYAPP_RELEASE are relative to that parent.
You can see from the above window that Windows translated the %MYAPP% variable into its value (you may have to close the ‘System Properties’ dialog and reopen it to see the change). Now lets move on to the batch files that will use these variables.
The Batch Files
So I want to be able to reach the following directories, both from the exploerer window and the command line:
- C:\dev\java\myApp
- C:\dev\java\myApp\trunk
- C:\dev\java\myApp\branch
You’ll need to decide where you want to put your batch files so Launchy can find them. Anywhere is fine, just remember where you put them. Because of old habit, I put all my batch files under home\bin. You can name these batch scripts whatever you like, but it should be something you can remember. You’ll be typing the names of these batch files into Launchy to navigate to these folders.
First, let’s create a batch file that will open up a command line on the “C:\dev\java\myApp” folder (remember that the MYAPP environment variable stores this value). I’m going to call this batch file “myApp.bat”.
myApp.bat
Simple enough? The first line changes directory into the MYAPP folder. The second line opens a command line prompt at that location.
I’ll do the same thing for the other locations that I want easy command line access to, using the other environment variables as the paths:
trunk.bat
release.bat
Now for the batch files that will open up explorers in these same locations. First for the ‘MYAPP’ location:
myAppex.bat
The first (and only) line opens an explorer window at the location specified in the MYAPP variable, in the default manner. The “/e” is an parameter on the explorer command that tells it to open in its default view (for more explorer options, see here).
Now to create the other explorer shortcuts:
trunkex.bat
explorer /e,%MYAPP_TRUNK%
relex.bat
explorer /e,%MYAPP_RELEASE%
Now we are ready to tell Launchy where these shortcut batch files are located.
Launchy
In order to get Launchy to be able to see and execute these batch files, we need to add them to its indexed directories. This is fairly simple to do. Open up Launchy by pressing ‘Alt-Space’, then right-click and choose ‘Directories’. Click the ‘Add’ button and choose the directory where you stored your batch files. Now select that directory from the left list, enter ‘.bat’ in the circled field below, and click the ‘Add’ button below the field. This tells Launchy that you want it to index all *.bat files in that directory.
Now open Launchy again, right-click on it and tell it to ‘Rebuid Index’. Now you should be able to ‘Alt-Space’ and type ‘myApp’ to open a command line to the MYAPP directory. And if you type ‘myAppex’, Lauchy will execute the myAppex.bat file and open an explorer window to tha myApp directory.
Doing this for all the file locations you spend a lot of time to will greatly decrease the time you spend manually navigating places, or even searching for the closest shortcut.