If you like Autohotkey, you probably have a lot of scripts you use or want to try out. Additionally, you will probably want to use those scripts on more than one machine, but potentially, you do not want to have all those scripts running on all machines. In my case, I only use Outlook on my work laptop, so all the Outlook hotkeys only need to be active on that machine, while at the same time I want to leverage Live Mesh (part of Windows Live Essentials) to sync all my scripts across machines. The combination of trying out scripts and selectively activating them makes keeping everything in one script a tedious task.
Enter Autoinclude. This is a very smart AHK script written by Scott Rippey that was published on Lifehacker some time ago. Follow the link for all the details, but what it basically does is conditionally generating a single AHK script from a set of folders containing scripts, and executing that single script. The only thing that you need to change in the AHK scripts that get included, is that you must add a comment on the first line with ";auto-execute" if you want to have auto-executing code in your particular script.
Setting up Autoinclude
You can read the Lifehacker post linked above to understand Autoinclude, so I will limit myself to a step-by-step instruction on how to set it up. This is what you do:
- In a folder that is synced by Live Mesh (or Dropbox or whatever else you prefer), set up a root folder for all your to-be-included scripts.
- On each machine, you need to create a specific Autoinclude AHK script. What makes it specific for each machine is the list of folders inside the root folder that you want to have included (see code below).
- Set up a Windows startup task that points to this Autoinclude script (easiest method: add a shortcut to the Startup folder in you Start menu)
Done! Whenever your startup task activates, the Autoinclude script will generate a new script that includes everything you told it to include, and execute it. This is the section of Autoinclude.ahk where you set your folders:
StartUp = C:\Users\tijmenvdk\_SkyDrive\scripts\prod\Autoinclude
Reloading your script tree from Launchy
To make editing and adding/removing scripts easier, you can add a shortcut to Launchy that points at your Autoinclude script and name it "reload script tree" (or similar). Better yet, add it to your Launchy-shortcut-generating-script with this line:
"%app_makelink%" /q "%folder_launchylinks%reload script tree.lnk" "C:\Users\tijmenvdk\Programs\AutoHotkey\Autoinclude.ahk" "" "" "" "7"
Just to give you an idea of what my scripts root folder looks like:
As you can see, I have added a simple naming convention: the script name includes the assigned hotkey, where applicable. This makes it very easy to find a particular script. "LoA" stands for "Launch or Activate", something I will explain in a later post.