A_UserName to be allowed in #include Topic is solved

Propose new features and changes
Acecool
Posts: 37
Joined: 10 Jan 2016, 18:25
Facebook: Acecool
Google: Acecool
GitHub: Acecool
Contact:

A_UserName to be allowed in #include

14 Apr 2016, 23:48

I don't understand why this one isn't a given to be authorized...

Code: [Select all] [Download] GeSHi © Codebox Plus

;
; My scripts... - Josh 'Acecool' Moser
;
#Include C:\Users\%A_UserName%\Dropbox\AutoHotKey
#include acecool_loader.ahk


Doesn't work, and because of the not so new username scheme for Windows with Microsoft Accounts which takes the first few chars then adds _### afterwards, makes it impossible to have old computers ( windows 7 and below ) which use local accounts with a full name, to keep the includes non-dynamic...

At the very least, we need A_DropBox variable for includes

I like simply double-clicking on the AHK exe and launching what I need automatically... I could use dropbox only and set it up to use that loader path, but that means accidentally loading AHK.exe opens an annoying help file, and using the working dir variable doesn't seem to always work for me....
-Josh 'Acecool' Moser
I teach various programming languages, game programming, etc... I am also taking on programming jobs as my health allows.
just me
Posts: 5425
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: A_UserName to be allowed in #include

15 Apr 2016, 03:08

#Include wrote:The path of a file or directory as explained below. This must not contain double quotes, wildcards, or variable references except %A_ScriptDir%, %A_AppData%, %A_AppDataCommon% and (in v1.1.11+) %A_LineFile%.
lexikos
Posts: 5991
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: A_UserName to be allowed in #include

15 Apr 2016, 22:51

#Include doesn't support general variable substitution; it simply does a string replacement for each supported variable. More variables supported = larger code.

I'm not sure I understand what you're trying to do, since it seems there would be multiple simple solutions. If you set the working directory when you launch AutoHotkey.exe, that will carry over to relative paths used with #include (in AutoHotkey v1, but not v2). Or you can simply Run the script after calculating its path instead of trying to #include it.
Acecool
Posts: 37
Joined: 10 Jan 2016, 18:25
Facebook: Acecool
Google: Acecool
GitHub: Acecool
Contact:

Re: A_UserName to be allowed in #include

26 Apr 2016, 16:50

just me wrote:
#Include wrote:The path of a file or directory as explained below. This must not contain double quotes, wildcards, or variable references except %A_ScriptDir%, %A_AppData%, %A_AppDataCommon% and (in v1.1.11+) %A_LineFile%.


I am aware of the quite restricted variables allowed to be used in #Include; while I understand why a whitelist is justified ( I have a lot of scripts and wanted to load them dynamically like my autoloader handles my game-mode, framework, etc... for a Source Engine Game ) for security reasons... I don't understand why the username var isn't allowed...

In short: I am requesting that %A_UserName% be added to the "authorized" variable list to be used in includes... ( for env vars, I don't see why you can't pass the string to Windows, if running Windows, to parse it; but for now I'll be more than happy with the username var being allowed because it will greatly simplify what I currently have to do to set up new shortcuts per pc to link directly to a different loader script which also has to be in the folder where the other files are [ I prefer keeping things organized ], adjusting it, placing it [ pain in Win 10 ] into the start menu, etc.... instead of simply running a .bat file I created which is all I'd need to do if %A_UserName% would be supported )
-Josh 'Acecool' Moser
I teach various programming languages, game programming, etc... I am also taking on programming jobs as my health allows.
wolf_II
Posts: 1961
Joined: 08 Feb 2015, 20:55

Re: A_UserName to be allowed in #include

26 Apr 2016, 17:53

I guess that just me wanted to hint that you can use A_AppData to work like this:

Code: [Select all] [Download] GeSHi © Codebox Plus

#Include %A_AppData%\..\..\Dropbox\AutoHotKey
#Include acecool_loader.ahk

It works on Win7.
Acecool
Posts: 37
Joined: 10 Jan 2016, 18:25
Facebook: Acecool
Google: Acecool
GitHub: Acecool
Contact:

Re: A_UserName to be allowed in #include

29 Apr 2016, 07:23

That works; thank you!

Last time I tried using ..\ I didn't seem to have any luck, but that could've been because I had an improper variable included...

I'd still like to see %A_UserName% included though :-)

This may help others too:




- Dropbox\AutoHotkey\Libraries\
Libraries folder; this is where things such as gdip should go...

- Dropbox\AutoHotkey\Setup\
The setup directory; it houses any files needing to be copied in addition to the setup bat file...

- AutoHotkey.ahk - Thanks wolf_II

Code: [Select all] [Download] GeSHi © Codebox Plus

#Include %A_AppData%\..\..\Dropbox\AutoHotKey
#Include acecool_loader.ahk


- Setup_AutoHotkey_on_this_PC.bat

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



All of this is dynamic aside from the base folder structure for DropBox... You can put any contents into your AutoHotkey.ahk file inside Dropbox\AutoHotkey\Setup\ and on new machines just run the bat file to have the file copied to my documents ( any existing file will be renamed for backup purposes ), and the libraries symbolic link will be created inside of the AHK installation dir ( any existing folder will be renamed for backup purposes )... Then just run autohotkey.exe - simple...

I'm still hoping to see %A_UserName% included...

Edit: Added config options..
Last edited by Acecool on 29 Apr 2016, 08:07, edited 1 time in total.
-Josh 'Acecool' Moser
I teach various programming languages, game programming, etc... I am also taking on programming jobs as my health allows.
User avatar
jeeswg
Posts: 4595
Joined: 19 Dec 2016, 01:58
Location: UK

Re: A_UserName to be allowed in #include

19 Jul 2017, 23:45

Thanks so much for this wolf_II. It's great, it means I don't have to ask for this as a feature request, I had wanted A_Desktop to be available, it was really inconveniencing me.

Although there is the small issue of different OSes having different AppData folders. for when you want to share scripts with people, unfortunately one needs one backtrack, the other needs two:
C:\Documents and Settings\%A_UserName%\Application Data
C:\Users\%A_UserName%\AppData\Roaming

Code: [Select all] [Download] GeSHi © Codebox Plus

;C:\Users\%username%\AppData\Roaming
;-> C:\Users\%username%\AppData
;-> C:\Users\%username%
;-> C:\Users\%username%\Desktop

#Include %A_AppData%\..\..\Desktop\MyScript.ahk


==================================================

lexikos wrote:More variables supported = larger code.

Is it really so bad? Is that just the nature of C++?

At least in AHK it's not too bad:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


Thanks for reading.
User avatar
jeeswg
Posts: 4595
Joined: 19 Dec 2016, 01:58
Location: UK

Re: A_UserName to be allowed in #include

25 Jul 2017, 01:50

If any variables were to be added, I would add these:
- A_UserName: allows you to have different folders for different users.
- A_Desktop: because Program Files is protected, and other folders are either obscure or used for other purposes, or differ between Windows versions, or don't have an existing AHK variable, and/or are filled with files/folders, Desktop is a good place to put a main folder/temporary files.
- A_AhkPath: this allows you to have scripts/folders that are AHK version specific e.g. '%A_AhkPath%.ahk' '%A_AhkPath%Dir\' or '%A_AhkPath%\..\' to refer to the AHK dir. This could eliminate a massive number of AHK v1/v2-related headaches.
coffee
Posts: 64
Joined: 01 Apr 2017, 07:55

Re: A_UserName to be allowed in #include

31 Jul 2017, 22:58

Junctions links or symbolic links. Similar to what wolf explained, but to any folder in your computer your heart desires. Making a self contained autohotkey script, that will create a junction link in your script directory pointing to any folder you want anywhere, is absolutely trivial.
Not even that, but "ahk v1/v2" headaches in terms of where functions/pieces of code are pulled from can be solved by doing that. Create your junction linking script, do the registry entries, again the script itself can take care of this, right click on folder background, click on your script context menu entry "link ahk v1 lib" or "link ahk v2 lib" or "link my favorite unorthodox folder to put my functions", boom. Done. Every custom folder setup is not a problem the autohotkey source should solve, but the user. After all, it's an automation tool, not sure why the hesitation on using it to solve something as basic as this.

You could do this and have your own explicit includes separate from the junctioned linked "Lib" folder.
#include %a_scriptdir%\explicit includes folder (which can itself be a junction link)
and then any #include filename.ahk will pull from there, and any #include <lib func> or autoincluded function will pull from the junctioned linked lib folder, since the local library has priority over the user and standard library. In this case, the standard library is given priority because the local library is pointing to it. You can even make this a short header on scripts that are not of your active autohotkey installation, that detects whether there's a lib folder and run mklink if not.
lexikos
Posts: 5991
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: A_UserName to be allowed in #include  Topic is solved

01 Apr 2018, 00:30

v1.1.28 allows all built-in variables in #Include.

Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 3 guests