Need help with a script ...

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
aShai
Posts: 18
Joined: 19 Jun 2015, 03:21

Need help with a script ...

19 Jun 2015, 03:50

Need help with a script that will send the {HOME} key to all ahk_class CabinetWClass | ahk_class ExploreWClass if active or exist.
I've been working on this for quite sometime and have yet to figure this out.
I've tried this and several other variations (Controlsend/ControlsendRaw/Send, etc...).

#Persistent
IfWinExist, ahk_class CabinetWClass
WinActivate
Send, {Home}
return

Help would be much apprenticed.
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: Need help with a script ...

19 Jun 2015, 04:19

IfWinExist, ahk_class CabinetWClass
{
WinActivate, ahk_class CabinetWClass
Send, {Home}
}
Else
Soundbeep, 199, 777
Return
User avatar
boiler
Posts: 16916
Joined: 21 Dec 2014, 02:44

Re: Need help with a script ...

19 Jun 2015, 08:26

That will only find one of the windows and operate on it. You need to use WinGet, List to identify all the matching windows, then create a loop to activate each one and Send, {Home} to each one individually.
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: Need help with a script ...

19 Jun 2015, 08:41

boiler wrote:That will only find one of the windows and operate on it. You need to use WinGet, List to identify all the matching windows, then create a loop to activate each one and Send, {Home} to each one individually.
That's a very nice idea.
Now, how is the codes ?
You can help him/her from top to bottom and every coner of it.
I, am, so busy at the moment.
See you then.
User avatar
boiler
Posts: 16916
Joined: 21 Dec 2014, 02:44

Re: Need help with a script ...

19 Jun 2015, 09:51

Code: Select all

WinGet, WinList, List, ahk_class CabinetWClass
Loop, %WinList%
{
	WinID := WinList%A_Index%
	WinActivate, ahk_id  %WinID%
	Send, {Home}
}
aShai
Posts: 18
Joined: 19 Jun 2015, 03:21

Re: Need help with a script ...

19 Jun 2015, 15:00

Thanks for the suggestions guys however these scripts do not work. Any more suggestions while I continue to figure this out?
User avatar
boiler
Posts: 16916
Joined: 21 Dec 2014, 02:44

Re: Need help with a script ...

19 Jun 2015, 16:44

By not working, do you mean it's not working in an ongoing manner? You need to put it in a loop or on a timer for that. As written, it does it once when you run it. But I know it works because when I replace CabinetWClass with Notepad and {Home} with Hello, it writes "Hello" into every open Notepad window I have open when I run it.

Perhaps sending {Home} to an active window of windows of class CabinetWClass does not have the result that you expect.

But if it's because it's not working as an ongoing script, try this:

Code: Select all

Loop
{
	WinGet, WinList, List, ahk_class CabinetWClass
	Loop, %WinList%
	{
		WinID := WinList%A_Index%
		WinActivate, ahk_id  %WinID%
		Send, {Home}
	}
	Sleep, 100
}
However, that will continuously keep sending {Home} to those windows over and over, which I didn't think is what you would want.
aShai
Posts: 18
Joined: 19 Jun 2015, 03:21

Re: Need help with a script ...

19 Jun 2015, 16:49

I think it's the class as you stated because when I first wrote the script it worked perfectly in notepad but not CabinetWClass. There has to be a way ........
aShai
Posts: 18
Joined: 19 Jun 2015, 03:21

Re: Need help with a script ...

19 Jun 2015, 16:50

Thanks again for your input.
User avatar
boiler
Posts: 16916
Joined: 21 Dec 2014, 02:44

Re: Need help with a script ...

19 Jun 2015, 17:01

I just ran it exactly as shown here, and it works with CabinetWClass as well for me. It does the exact same thing in all of my explorer windows as if I had hit the Home key myself in them. Is that what you're expecting to happen?
aShai
Posts: 18
Joined: 19 Jun 2015, 03:21

Re: Need help with a script ...

19 Jun 2015, 18:18

Well I'm not sure what's going on but it's not working in the manner I intended for it to work (If I click it it presses the home key like the scripts I previously made, but not when I open up other windows). I even added #Persistent to see if that would help, nope!
aShai
Posts: 18
Joined: 19 Jun 2015, 03:21

Re: Need help with a script ...

19 Jun 2015, 18:23

Again I'm trying to get the script to send the home key (select/highlight the first item in the folder) to each instance of class of window once opened.
User avatar
boiler
Posts: 16916
Joined: 21 Dec 2014, 02:44

Re: Need help with a script ...

19 Jun 2015, 22:27

No, you actually didn't say that before. The "once opened" is the key new thing you mentioned. The script I posted does exactly what your first post says you wanted. When you run the script, it will do that for all windows that exist at the time. If you want it to operate on windows as they open and only as they are first opened, that's different. It can be made to do that. Persistent just keeps the script open, it doesn't make it keep checking or running it from the beginning. You have to add the flow and control into the code yourself to make it do what you want when you want. If you use the version I showed with the Loop in it, then it will constantly be sending {Home} to all of them. It sounds like you want it to just check for new ones, which is more involved. That can be done.

You need to have it keep an updated array of all the existing IDs that match the criteria (I showed you how to store them in an array). Then you need to have it re-check for all the ones that currently exist (using the method shown) and compare them to the ones in the array of last known group of windows. Then if it finds a new one (i.e., not in the list), it would send {Home} to that one (and update the list of last known windows for the next comparison).

You may want to try to make a script do that per that direction and post it here if you can't get it to work. It's a lot better for learning if you try working out the logic yourself first.
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: Need help with a script ...

19 Jun 2015, 22:35

Easy Dear "boiler"..
>You can help him/her from top to bottom and every coner of it.
Actually, You can not help him.
That is his own business.
aShai
Posts: 18
Joined: 19 Jun 2015, 03:21

Re: Need help with a script ...

19 Jun 2015, 22:39

That's what I've been doing relentlessly for the past few days, I put aside my pride and came here for some help. My apologies if I didn't make the purpose of the script crystal clear on my original post. My thoughts were active included on open.
User avatar
boiler
Posts: 16916
Joined: 21 Dec 2014, 02:44

Re: Need help with a script ...

19 Jun 2015, 23:06

The difference now is that I showed you some things that would allow you to do it, and I outlined the logic for you. I'll post something that works, but I think it would still be a good exercise for you to try it yourself using the approach I described.
aShai
Posts: 18
Joined: 19 Jun 2015, 03:21

Re: Need help with a script ...

19 Jun 2015, 23:18

Again, that's what I've been doing relentlessly for the past few days even with what you've outlined the time I've spent working on this particular script has diminished my patience on it. I have many more scripts to create, this one is quite the challenge. Thanks again for your help.
User avatar
boiler
Posts: 16916
Joined: 21 Dec 2014, 02:44

Re: Need help with a script ...

19 Jun 2015, 23:30

You're welcome. Here's a working script:

Code: Select all

LastCount := 0
Loop
{
	WinGet, WinList, List, ahk_class CabinetWClass
	Loop, %WinList%
	{
		Outer := A_Index
		Found := 0
		Loop, %LastCount%
		{
			if (WinList%Outer% = LastWinID%A_Index%)
			{
				Found := 1
				break
			}
		}
		if !Found
		{
			WinID := WinList%Outer%
			WinActivate, ahk_id  %WinID%
			Send, {Home}
		}
	}
	LastCount := WinList
	Loop, %WinList%
		LastWinID%A_Index% := WinList%A_Index%
	Sleep, 100
}
aShai
Posts: 18
Joined: 19 Jun 2015, 03:21

Re: Need help with a script ...

20 Jun 2015, 00:38

Thanks!!! WoW, impressive!!! I learn better with examples. Now I'm going to get the script to send home once I click on a folder inside the initial window. To achieve that it would Involve WinGet and Loop correct?
User avatar
boiler
Posts: 16916
Joined: 21 Dec 2014, 02:44

Re: Need help with a script ...

20 Jun 2015, 08:25

If I understand what you want it to do, you want it to automatically send Home to it again, but only when you open a new folder in that window. Is that correct? What I think would be necessary would be to constantly monitor the contents of the Edit1 control (which displays the current path) of the active window (if it is this class of window) using ControlGet, and wait for it to change. Then when it does, send Home to the window.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Rohwedder and 336 guests