AutoHotkey Community

It is currently May 27th, 2012, 12:26 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: June 11th, 2005, 8:30 pm 
Offline

Joined: June 2nd, 2005, 8:25 am
Posts: 48
Location: Moscow
I run my script at startup used a Registry record:
Code:
RegWrite, REG_SZ, HKCU, Software\Microsoft\Windows\CurrentVersion\Run, %A_ScriptName%, %A_ScriptFullPath%

The script .ahk file is located in following directory:
C:\Documents and Settings\Dmitry Lyudmirsky\My Documents\AutoHotkey
However when runnig the script shows following:
A_WorkingDir = C:\Documents and Settings\Dmitry Lyudmirsky
A bug?


Report this post
Top
 Profile  
Reply with quote  
PostPosted: June 11th, 2005, 8:44 pm 
Offline

Joined: April 5th, 2005, 10:50 pm
Posts: 133
Try to add the path where the AHK installed on your machine
Code:
RegWrite, REG_SZ, HKCU, Software\Microsoft\Windows\CurrentVersion\Run, %A_ScriptName%, c:\autohotkey\autohotkey.exe %A_ScriptFullPath%

Not tested.!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 12th, 2005, 10:25 am 
Offline

Joined: June 2nd, 2005, 8:25 am
Posts: 48
Location: Moscow
MYYM,
I've tested your suggestion. It doesn't work. :(


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 12th, 2005, 11:41 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
I don't think it's a bug because the script's working directory doesn't have any code behind it. It just accepts whatever it was given. Thus, this working directory seems to be caused by the OS when it launches things in the Run subkey.

To work around this, change the working directory at the top of the script:
SetWorkingDir C:\Documents and Settings\Dmitry Lyudmirsky\My Documents\AutoHotkey


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 12th, 2005, 4:06 pm 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2545
IMO you're better off using A_ScriptDir to refer to a file in the script's directory than depending on Windows to set the proper working directory...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 14th, 2005, 8:48 am 
Offline

Joined: June 2nd, 2005, 8:25 am
Posts: 48
Location: Moscow
Chris,
but why A_WorkingDir and A_ScriptDir might be different at the startup moment?
For example I create Test.ahk consisting of two lines only:
Code:
RegWrite REG_SZ, HKCU, Software\Microsoft\Windows\CurrentVersion\Run, %A_ScriptName%, %A_ScriptFullPath%
MsgBox A_WorkingDir = %A_WorkingDir%`nA_ScriptDir = %A_ScriptDir%

run it and then restart my computer. Immediately after restart I see MsgBox with following:
A_WorkingDir = C:\Documents and Settings\Dmitry Lyudmirsky
A_ScriptDir = C:\Documents and Settings\Dmitry Lyudmirsky\My Documents\AutoHotkey


You suggest to apply
Code:
SetWorkingDir %A_ScriptDir%

at the top of my script.
This is a good idea, but my problem rise at the compiling time. The compiler does not able to find an IncludingFile located in the %A_ScriptDir% directory to process a line like this:
Code:
#Include IncludingFile

Unfortunately SetWorkingDir does not effect during the compilation.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 14th, 2005, 12:55 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Dmitry wrote:
why A_WorkingDir and A_ScriptDir might be different at the startup moment?
Because A_WorkingDir depends solely on the working directory specified by the process that launched the script. To retain flexibility, the program does not try to override this.

Quote:
The compiler does not able to find an IncludingFile located in the %A_ScriptDir% directory
There is a plan to provide a means to change the working directory for #Include files. In the meantime -- assuming there's no way you can have the program launch in the working directory you really want -- you will probably have to specify the full path with each #Include in the script.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 14th, 2005, 1:49 pm 
Offline

Joined: June 2nd, 2005, 8:25 am
Posts: 48
Location: Moscow
Quote:
There is a plan to provide a means to change the working directory for #Include files.

I don't need to use a special directory for #Include files. All my #Include files are located in the SAME working directory as script files.
Quote:
you will probably have to specify the full path with each #Include in the script.

It means every time when I want to move or rename my working directory or bring my scripts on another computer I must rewrite all my scripts! Not nice, isn't it?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 14th, 2005, 1:59 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Dmitry wrote:
It means every time when I want to move or rename my working directory or bring my scripts on another computer I must rewrite all my scripts!
The fault here lies with the process that launches the script. It is specifying the wrong working directory. You could try having the registry launch a helper script that launches the main script by specifying the correct working directory:

Run C:\Scripts\Main Script.ahk, %A_ScriptDir%

I've made a note to see if A_ScriptDir can be directly supported by #Include. That would make this easier. Thanks for the idea.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 15th, 2005, 9:10 am 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2545
Dmitry wrote:
This is a good idea, but my problem rise at the compiling time. The compiler does not able to find an IncludingFile located in the %A_ScriptDir% directory to process a line like this:
Code:
#Include IncludingFile

Unfortunately SetWorkingDir does not effect during the compilation.
Dmitry wrote:
It means every time when I want to move or rename my working directory or bring my scripts on another computer I must rewrite all my scripts! Not nice, isn't it?

In case you weren't aware, if you have compiled the script the directory name with the Include files won't matter as the data from the Include files is added to the compiled script.
Quote:
Lines displayed in the main window via ListLines or the menu View->Lines are always numbered according to their physical order within their own files. In other words, including a new file will change the line numbering of the main script file by only one line (except for compiled scripts, which merge their included files into one big script at the time of compilation).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 15th, 2005, 10:51 am 
Offline

Joined: June 2nd, 2005, 8:25 am
Posts: 48
Location: Moscow
corrupt,
thank you, i know this.
The surprise is that the compiler sometimes can not find "#Include FileNameWithoutPath.ahk" files stored in the SAME directory as the script file processed. :(


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 15th, 2005, 10:59 am 
Offline

Joined: June 2nd, 2005, 8:25 am
Posts: 48
Location: Moscow
Chris,
please,
bring the compiler to search #Include files in %A_ScriptDir% as well as in %A_WorkingDir%!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 15th, 2005, 11:35 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
I checked the code for ahk2exe and it does set the working directory to the script's own directory. Has anyone else had problem with ahk2exe not being able to find include files in the script's own folder?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 16th, 2005, 8:10 am 
Offline

Joined: June 2nd, 2005, 8:25 am
Posts: 48
Location: Moscow
Oh, I'm sorry, I've regard the "compiler" word incorrectly. I meant the interpreter, not the compiler. My problem relates to the AutoHotkey.exe, not to the Ahk2Exe.exe.
I run a set of MyScript.ahk as documents on Windows startup. In fact I launch the AutoHotkey.exe to run theese scripts. When they contain some #Include instructions, then AutoHotkey.exe searches IncludingFiles.ahk only in "working directory" -- DOS-like "current directory". This directory may be not the same as "MyScript with IncludingFiles" directory.
All is Ok when MyScript.ahk is running from Windows Explorer window or through a shortcut having explicit "Start in" data.
But AutoHotkey.exe does NOT find including files when a "current directory" is not the MyScript directory. It happens, for example, on Windows startup.
Of course I can avoid this problem by writing something like this:
Code:
#Include C:\Documents and Settings\User Name\My Documents\AutoHotkey Projects\Autorun Scripts\Including.ahk

in MyScript.ahk.
But instead, it would be better do without #Include at all, simply transfer some lines required from Including.ahk into MyScript.ahk directly.
That is why I ask to teach AutoHotkey.exe inspecting A_ScriptDir too.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 16th, 2005, 1:14 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Thanks for clarifying.

I'll try to make #Include support for A_ScriptDir. For example:
#Include %A_ScriptDir%\My Include.ahk

The reason for doing it this way rather than searching automatically in A_ScriptDir is that it might break existing scripts that rely on #Include files not being found depending on the working directory. This was a requested feature and is the reason for #Include's "ignore" option (*i).


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group