library location

Get help with using AutoHotkey and its commands and hotkeys
sttrebo
Posts: 68
Joined: 27 Jan 2014, 12:31

library location

15 Nov 2017, 09:19

Hi-
From what I've read, the location for the library functions is fixed. Are there any workarounds? I'd prefer to keep my library functions in my dropbox, but my dropbox is a different location on my different computers (work, home, etc). Any ideas?

thanks
sttrebo
Posts: 68
Joined: 27 Jan 2014, 12:31

Re: library location

15 Nov 2017, 11:14

thanks, got that. doesn't really answer my question though, but maybe i wasn't clear enough (sorry too early in the morning). i want to have the same script(s) execute on multiple machines with all the #includes pointing to a dropbox location that is different on each machine (c:\users\somenamehere\dropbox\ahk\lib). note the 'somenamehere' is different for each computer.
BoBo
Posts: 3854
Joined: 13 May 2014, 17:15

Re: library location

15 Nov 2017, 12:04

As an advanced noob I'd think about a workaround, where we are changing one of those (env) variables on-the-fly that are listed as valid #Include-references ... :shh:
User avatar
Gio
Posts: 1068
Joined: 30 Sep 2013, 10:54
Location: Brazil

Re: library location

15 Nov 2017, 12:13

Hello sttrebo.
sttrebo wrote:thanks, got that. doesn't really answer my question though, but maybe i wasn't clear enough (sorry too early in the morning). i want to have the same script(s) execute on multiple machines with all the #includes pointing to a dropbox location that is different on each machine (c:\users\somenamehere\dropbox\ahk\lib). note the 'somenamehere' is different for each computer.
If the problem is basically the name of the users, just use the built-in variable A_UserName to build a UserName dependant full path. If something else may change in the path, you have to study what is changing and how it's changing, and than make a code to account for that too. If you can't do it by yourself, we will need some samples of the different file paths to provide further help in this case.

Best wishes.
sttrebo
Posts: 68
Joined: 27 Jan 2014, 12:31

Re: library location

15 Nov 2017, 12:24

thanks, here's my dilema:
work pc#1 - c:\users\myworklogin\dropbox\ahk\lib
work pc#2 - d:\dropbox\ahk\lib
work pc#3 - c:\users\someotherlogin\dropbox\ahk\lib
home pc#1 - c:\users\mydocuments\autohotkey\lib

BoBo above had an note to maybe change one of those (env) variables on-the-fly (the ones that are compatible with #include). I didn't think you could? is there a way to?
list
Posts: 197
Joined: 26 Mar 2014, 14:03
Contact:

Re: library location

15 Nov 2017, 12:31

Perhaps

1. mklink: http://autohotkey.com/board/topic/86191 ... /?p=549034
2. or just copy files to the "correct" location using a batch file or script - https://autohotkey.com/boards/viewtopic.php?t=15926
User avatar
Gio
Posts: 1068
Joined: 30 Sep 2013, 10:54
Location: Brazil

Re: library location

15 Nov 2017, 12:38

work pc#1 - c:\users\myworklogin\dropbox\ahk\lib
work pc#2 - d:\dropbox\ahk\lib
work pc#3 - c:\users\someotherlogin\dropbox\ahk\lib
home pc#1 - c:\users\mydocuments\autohotkey\lib
Is the ahk folder always the folder in which the script will be located? If it is, you use the built-in variable A_ScriptDir to build a path up to the \lib folder.

Otherwise it seem that you are out of luck in the file patterns section. Even the harddrive is changing in the samples. Maybe you can still have the script use some Loop (Files & Folders) to search for the dropbox folder by name and than feed the file path accordingly, but i would only do this in a last case scenario though since it can take quite a while for the script to finish the loop. Is replacing the location of the lib in said computers to follow some kind of planned pattern out of question? (this would be a better solution).

Either way, if you choose to make the Loop (Files & Folders) searching routine, do remeber you can have conditionals to skip some huge folders that obviously won't hold the lib (i.e., windows folder). This could reduce the processing time to a more manageable figure.
sttrebo
Posts: 68
Joined: 27 Jan 2014, 12:31

Re: library location

15 Nov 2017, 12:43

thanks, i forgot about the symbolic link idea. that might be simplest way.
I was also thinking to just put together a conditional filecopy script. just need to add into it a date or time check to make sure it doesn't spend time copying files that are already there.
BoBo
Posts: 3854
Joined: 13 May 2014, 17:15

Re: library location

15 Nov 2017, 17:21

Just for the records (so a pro-bro might come up with a solution how to tweak #Include's path options via an environment variable) ...
https://msdn.microsoft.com/de-de/librar ... s.85).aspx

https://autohotkey.com/docs/commands/EnvSet.htm
https://autohotkey.com/docs/commands/EnvGet.htm

PS. Instead of using %A_Username% to personalize a path try %UserProfile% ...
MsgBox % A_Username "`n" UserProfile
User avatar
davebrny
Posts: 84
Joined: 05 Dec 2016, 06:26

Re: library location

15 Nov 2017, 20:06

would using something similar to this be an option?

- make each computer/script loop through the dropbox folder and generate a list of ahk files
- save the list somewhere locally on your computer (not in dropbox)
- #include that list into your script.

that last step might be the dealbreaker if you have a lot a scripts though.
for a long while after i started using autohotkey i was completely unaware of the library folder option so i used this method to include a list of functions into other scripts, but i mainly just throw everything into 1 main script so i didnt have to include the functions list into other scripts that often either
sttrebo
Posts: 68
Joined: 27 Jan 2014, 12:31

Re: library location

15 Nov 2017, 20:20

I ended up putting this script together. It does several things for me:
- finds my dropbox path, computer name (for ID purposes) and outputs that to a text file in %A_Temp%. I have other scripts that reads that file into variables.
- then it checks for/creates a Lib directory and xcopys over files as needed based on file date
- runs the rest of my ahk startups.

Seems to do all I need and it is machine/structure independent (as far as I can tell so far).

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

; dropbox path
EnvGet, appdata_Loc, LOCALAPPDATA
FileRead, string, %appdata_Loc%\DropBox\info.json
Path_Loc := (InStr(string, "path", false)) + 8
Host_Loc := (InStr(string, "host", false)) - 4
Path_Len := Host_Loc - Path_Loc
DB_Path := StrReplace(SubStr(string, Path_Loc, Path_Len), "\\", "\")
;

; todo path
ToDo_Path = %DB_Path%\todo
;

; machine name
RegRead, Mach_Name, HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName, ComputerName
;

; write sections
IniWrite, %DB_Path%, %A_Temp%/AHK.txt, DropBox, Location
IniWrite, %ToDo_Path%, %A_Temp%/AHK.txt, ToDo, Location
IniWrite, %Mach_Name%, %A_Temp%/AHK.txt, Machine, Name
;

; setup library
Source = %DB_Path%\AHK\Lib
Destination = %A_MyDocuments%\AutoHotkey\Lib
IfNotExist, %A_MyDocuments%\AutoHotkey\Lib
	FileCreateDir, %A_MyDocuments%\AutoHotkey\Lib
Run % comspec " /c xcopy """ Source """ """ Destination """ /d"
;

; complete bootup
startup_file = AHK Startup - %Mach_Name%.ahk
Run %DB_Path%\AHK\%startup_file%
;
exitapp

Return to “Ask For Help”

Who is online

Users browsing this forum: BeSu, Chunjee, DaveT1, mikeyww, sachin24 and 51 guests