Instead of sophisticated and neat, how about something simple and necessary.
Add
A_MyDocuments as a valid variable in the
#Include directive. With this, one can place his include folder next to his lib folder and reference it with the same code on different machines, and simply use
template.ahk to maintain a consistent list of common include files (which you can remove from or add to each script as needed). For example:
- Home: D:\AutoHotkey\include
- Work: C:\Documents and Settings\User.Name\MyPersonalFolder\AutoHotkey\include
Code:
#Include %A_MyDocuments%\AutoHotkey\include
#Include IncludeFile1.ahk
#Include IncludeFile2.ahk
#Include IncludeFile3.ahk
This could help some people, including me, to sync their scripts on multiple machines. Here is my code if it helps you add this to the next version:
The following instructions are in the format:[STEP 1 - Upgrade AutoHotkey]
Find
codeInsert
code[STEP 2 - Upgrade AHK2EXE]
Find
codeInsert
code[STEP 3 - Upgrade AHK2EXE]
Find
codeInsert
code[STEP 1 - Add A_MyDocuments to the #Include directive in AutoHotkey]In Script.cpp of AutoHotkey, find the following code (should be line 2576):
Code:
if (strcasestr(parameter, "%A_AppDataCommon%")) // v1.0.45.04.
{
BIV_AppData(buf, "A_AppDataCommon");
StrReplace(parameter, "%A_AppDataCommon%", buf, SCS_INSENSITIVE, 1, space_remaining);
}
Paste this code immediately after it (should be line 2581):
Code:
if (strcasestr(parameter, "%A_MyDocuments%"))
{
BIV_MyDocuments(buf, "A_MyDocuments");
StrReplace(parameter, "%A_MyDocuments%", buf, SCS_INSENSITIVE, 1, space_remaining);
}
[STEP 2 - Add A_MyDocuments to the #Include directive in AHK2EXE]NOTE: All changes after this point are for AHK2EXE only
In Application.cpp find the following code (should be line 1499):
Code:
if (strcasestr(filename, "%A_AppDataCommon%")) // v1.0.45.04.
{
GetAppData(true, buf);
StrReplace(filename, "%A_AppDataCommon%", buf, false); // Overflow is too unlikely, so it isn't checked.
}
Paste this immediately after it (should be line 1504):
Code:
if (strcasestr(filename, "%A_MyDocuments%"))
{
GetMyDocuments(buf);
StrReplace(filename, "%A_MyDocuments%", buf, false); // Overflow is too unlikely, so it isn't checked.
}
[STEP 3 - Teach AHK2EXE how to find the "My Documents" folder]In the same source file (Application.cpp), find the following code (should be line 1091):
Code:
void GetAppData(bool aGetCommon, char *aBuf)
// Caller must ensure that buf is at least MAX_PATH in size.
{
*aBuf = '\0'; // Set default.
if (aGetCommon)
RegReadString(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"
, "Common AppData", aBuf, MAX_PATH);
if (!*aBuf) // Either the above failed or we were told to get the user/private dir instead.
RegReadString(HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"
, "AppData", aBuf, MAX_PATH);
}
Insert this function after it (should be line 1105):
Code:
void GetMyDocuments(char *aBuf)
// Caller must ensure that buf is at least MAX_PATH in size.
{
*aBuf = '\0'; // Set default.
RegReadString(HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"
, "Personal", aBuf, MAX_PATH);
}