Opening folders

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Guest

Re: Opening folders

22 Aug 2017, 10:27

This time it gets stuck if ErrorLevel is false; should I have a subroutine that's:

Code: Select all

CheckErrorLevel:
{
WinWaitActive, , , 0.5
If ErrorLevel
	Return
else
	Return
}
? It does seem to work, but it looks rather odd to me. Also, by adding WinWaitActive, , , 0.5 I should remove it from the main code, should I?
User avatar
DyaTactic
Posts: 221
Joined: 04 Apr 2017, 05:52

Re: Opening folders

23 Aug 2017, 03:02

It does show the textbox on my pc. Is the window centered anyway?
Also try this code, it will show the ErrorLevel evaluated by ‘If ErrorLevel’.

Code: Select all

^!d::
{
	Run C:\Documents\
	WinWaitActive, F,,1
	Gosub, CheckErrorLevel
	Gosub, Center
	Return
}

Center:
{
	WinGetPos, , , WinW, WinH, A
	WinMove, A, , A_ScreenWidth/2-WinW/2, A_ScreenHeight/2-WinH/2-60
	Return
}

CheckErrorLevel:
{
	MsgBox, ErrorLevel = '%ErrorLevel%'
	If ErrorLevel
		MsgBox, Text
	Return
}
MauroG
Posts: 60
Joined: 11 Jul 2017, 05:52

Re: Opening folders

23 Aug 2017, 04:38

DyaTactic wrote:It does show the textbox on my pc. Is the window centered anyway?
Yesterday it wasn't, today the code works for me too, textbox and all, no idea what happened; it just loses focus the first time it happens, so it doesn't center it.

And now it seems to work like this:

Code: Select all

^!d::
{
	Run C:\Documents\
	WinWaitActive, Documents,,1
	Gosub, CheckErrorLevel
	Gosub, Center
	Return
}

Center:
{
	WinGetPos, , , WinW, WinH, A
	WinMove, A, , A_ScreenWidth/2-WinW/2, A_ScreenHeight/2-WinH/2-60
	Return
}

CheckErrorLevel:
{
	Return
}
while yesterday the CheckErrorLevel part written that way didn't worked it ErrorLevel was 0; again, no idea what happened.

... then it didn't worked in the whole script, but it started working. My computer is haunted :shock: Will try this code and see if it works, thanks.
User avatar
DyaTactic
Posts: 221
Joined: 04 Apr 2017, 05:52

Re: Opening folders

23 Aug 2017, 04:46

It sometimes occurs to me too with other Run commands. I worte a safety like "is it active > No > Activate > Is it active? > No Return, or Yes > continue."

Code: Select all

Run ...
WinWait, Documents, , 2
If !ErrorLevel
	WinActivate, Documents
If the problem returns you can try this.
MauroG
Posts: 60
Joined: 11 Jul 2017, 05:52

Re: Opening folders

23 Aug 2017, 06:09

In my case the folder didn't even open, so maybe that wouldn't work? I'll wait if the issue reappears and see if the current code work, and I'll keep that in mind, thanks.
MauroG
Posts: 60
Joined: 11 Jul 2017, 05:52

Re: Opening folders

25 Aug 2017, 08:18

Now I'm trying this code:

Code: Select all

^!d::
{
	Run C:\Documents\
	WinWaitActive, D,,0.5
	Gosub, CheckErrorLevel
	Gosub, Center
	Return
}


Center:
{
	WinGetPos, , , WinW, WinH, A
	WinMove, A, , A_ScreenWidth/2-WinW/2, A_ScreenHeight/2-WinH/2-60
	Return
}

CheckErrorLevel:
{
	if ErrorLevel
		MsgBox, The window does not exist.
	else
		MsgBox, The window exists.
	Return
}
and it opens the folder and centers it; as messagebox, it shows NoError. Now I'll wait with the normal code to see what happens when the actual issue happens.

(By the way, first time I run the script sometimes it doesn't center the folder.)
MauroG
Posts: 60
Joined: 11 Jul 2017, 05:52

Re: Opening folders

28 Aug 2017, 05:33

It seems it doesn't solve the issue: I got the error, but after that the hotkey didn't work anymore: it never opened the folder and alway gave the error. Not ever reloading the script solved it, I had to restart the Explorer service.
User avatar
DyaTactic
Posts: 221
Joined: 04 Apr 2017, 05:52

Re: Opening folders

28 Aug 2017, 05:48

Can you check the history of lines executed via the traymenu > Open? Hopefully you find something there.
MauroG
Posts: 60
Joined: 11 Jul 2017, 05:52

Re: Opening folders

28 Aug 2017, 06:13

Now it's reset since I reloaded the script, but will do as soon as I get the issue again, thanks for the tip!
MauroG
Posts: 60
Joined: 11 Jul 2017, 05:52

Re: Opening folders

30 Aug 2017, 13:22

Unfortunately there isn't much:

020: {
021: Run,C:\Documents\
022: WinWaitActive,Documents,,1 (1.00)
023: Gosub,CheckErrorLevel
128: {
129: if (ErrorLevel = 0)
132: MsgBox,Error (1.81)
133: Return
User avatar
DyaTactic
Posts: 221
Joined: 04 Apr 2017, 05:52

Re: Opening folders

01 Sep 2017, 04:43

So Errorlevel was 1. Is that as expected? It does not center the window which could not be found, that is how it should be. Wat else was going wrong here?
MauroG
Posts: 60
Joined: 11 Jul 2017, 05:52

Re: Opening folders

01 Sep 2017, 04:52

That after that error that hotkey doesn't work anymore, the folder never opens: if I press ^!d, nothing happens, it's like the Run in that part of the script froze.
User avatar
DyaTactic
Posts: 221
Joined: 04 Apr 2017, 05:52

Re: Opening folders

01 Sep 2017, 05:26

It should have executed line 24: GoSub, Center. I don't know why that is not happening.
Does this always happen when the window does not show up (i.e. ErrorLevel = 1)?

You wanted the routine to stop when Errorlevel is 1, don't you? I belive the Exit command will stop both the execution of the label and the calling routine.

Code: Select all

CheckErrorLevel:
{ ; This block is not necessary.
	if ErrorLevel
	{
		MsgBox, The window does not exist.
		Exit
	} Else
		MsgBox, The window exists.
	Return
}
MauroG
Posts: 60
Joined: 11 Jul 2017, 05:52

Re: Opening folders

01 Sep 2017, 05:32

I think it didn't execute Center, if it did it was on the message box; I'll check that out to be sure. As far as I remember this always happens if the windows doesn't open: error, then that hotkey doesn't work anymore (but the rest on other folders do).

I'll try adding the Exit and let you know when I get again the issue, thanks.
User avatar
DyaTactic
Posts: 221
Joined: 04 Apr 2017, 05:52

Re: Opening folders

01 Sep 2017, 05:41

That behaviour could be caused when the subroutine (^!d) is still running. The question I can't resolve is why is doesn't continue with the rest of the label after line '133: Return' is executed. It should return the the next line after GoSub, CheckErrorLevel.
MauroG
Posts: 60
Joined: 11 Jul 2017, 05:52

Re: Opening folders

02 Sep 2017, 16:28

Unfortunately it didn't solve the issue:

070: Run,C:\Documents\
071: WinWaitActive,Documents,,1 (1.00)
072: Gosub,CheckErrorLevel
128: if ErrorLevel
130: MsgBox,Error (6.83)
131: Exit (1.58)
069: {
070: Run,C:\Documents\
071: WinWaitActive,Documents,,1 (1.00)
072: Gosub,CheckErrorLevel
128: if ErrorLevel
130: MsgBox,Error (1.88)
131: Exit (7.14)

It still doesn't run that hotkey anymore.

I also changed the code to run Center only if ErrorLevel = 0, otherwise it would center windows already opened (it did run Center, I forgot about it, sorry).

For now the only workaround I found is to have a code to restart Explorer, so the hotkey works again.
User avatar
DyaTactic
Posts: 221
Joined: 04 Apr 2017, 05:52

Re: Opening folders

04 Sep 2017, 07:10

So the conclusion is now that Windows is not able to handle this hotkey properly... Funny.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Draken, Google [Bot], oktavimark and 311 guests