How to run a script only if chrome is at the current window ? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
hancre
Posts: 251
Joined: 02 Jul 2021, 20:51

How to run a script only if chrome is at the current window ?

17 Sep 2021, 21:50

I tried the following script. But it has two problems.

Code: Select all

WinGetClass, class, A
If winclass("Chrome_WidgetWin_1") 
  !q:: run https://www.youtube.com/feed/history 
  !w:: run https://www.youtube.com/playlist?list=WL 
 return


1st : it seems that it works only for only the 1st chrome window
becasue I use 'If winclass("Chrome_WidgetWin_1")'.
I hope that it would be run at the other chrome windows.
2nd : It shows an error like the attached image.

How can i fix the issue?
Thanks for any help in advance.
Attachments
temp_0918_003.jpg
temp_0918_003.jpg (27.8 KiB) Viewed 1507 times
User avatar
mikeyww
Posts: 28989
Joined: 09 Sep 2014, 18:38

Re: How to run a script only if chrome is at the current window ?  Topic is solved

17 Sep 2021, 21:57

If you are going to make up your own function, you would need to define it. You could use the following.

Code: Select all

#IfWinActive ahk_exe chrome.exe
!q:: Run, chrome.exe https://www.youtube.com/feed/history
!w:: Run, chrome.exe https://www.youtube.com/playlist?list=WL
#IfWinActive
Or:

Code: Select all

#IfWinActive ahk_exe chrome.exe
!q::allChrome("https://www.youtube.com/feed/history")
!w::allChrome("https://www.youtube.com/playlist?list=WL")
#IfWinActive

allChrome(url) {
 WinGet, win, List, ahk_exe chrome.exe
 Loop, %win% {
  WinActivate, % "ahk_id " win%A_Index%
  Send ^t
  Send {Text}%url%`n
 }
}
hancre
Posts: 251
Joined: 02 Jul 2021, 20:51

Re: How to run a script only if chrome is at the current window ?

17 Sep 2021, 22:20

mikeyww wrote:
17 Sep 2021, 21:57
The first code works in chrome ( I removed blank and comma(,) in the first code. )
I didn't try the 2nd code.
But I think The second code would be useful for other programs.

Thank you for your help.
Have a nice weekend. ^^*

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], ByronicZero, leothlon and 116 guests