How to send commands into Chrome? Javascript commands

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Weltall900
Posts: 2
Joined: 30 Nov 2022, 13:39

How to send commands into Chrome? Javascript commands

Post by Weltall900 » 06 Dec 2022, 13:56

Hello, I've got a bunch of javascript commands I need entered into Chrome. I was having AHK just manually put them into the Chrome URL bar as "javascript:addMultiPickerItem('about','3874398',userAdded);" then click ENTER. Then the next one "javascript:addMultiPickerItem('about','7374290',userAdded);" then click ENTER. But I've got hundreds of lines of these basic Javascript commands that I need done in Chrome. Is there an easier way to get this list of commands into Chrome?

For example, here's what I've been doing

Code: Select all

Sleep, 200
WinActivate, ahk_exe chrome.exe
Sleep, 200
Send, ^l
Sleep, 200
Send, javascript:addMultiPickerItem('about','7374290',userAdded);
Sleep, 200
Send, {Enter}
Sleep, 200
Send, ^l
Sleep, 200
Send, javascript:addMultiPickerItem('about','6504208',userAdded);
Sleep, 200
Send, {Enter}
Sleep, 200
Send, ^l
Sleep, 200
Send, javascript:addMultiPickerItem('about','9850638',userAdded);
Sleep, 200
Send, {Enter}
Sleep, 200
Send, ^l
Sleep, 200
Send, javascript:addMultiPickerItem('about','4520853',userAdded);
Sleep, 200
Send, {Enter}
Sleep, 200
[Mod edit: [code][/code] tags added.]

Etc. There's gotta be a better way to do this and send all these into Chrome. The only variables that will change are the numbers next to about.

sashaatx
Posts: 333
Joined: 27 May 2021, 08:27
Contact:

Re: How to send commands into Chrome? Javascript commands

Post by sashaatx » 06 Dec 2022, 16:48

Weltall900 wrote:
06 Dec 2022, 13:56
Hello, I've got a bunch of javascript commands I need entered into Chrome. I was having AHK just manually put them into the Chrome URL bar as "javascript:addMultiPickerItem('about','3874398',userAdded);" then click ENTER. Then the next one "javascript:addMultiPickerItem('about','7374290',userAdded);" then click ENTER. But I've got hundreds of lines of these basic Javascript commands that I need done in Chrome. Is there an easier way to get this list of commands into Chrome?

For example, here's what I've been doing

Code: Select all

Sleep, 200
WinActivate, ahk_exe chrome.exe
Sleep, 200
Send, ^l
Sleep, 200
Send, javascript:addMultiPickerItem('about','7374290',userAdded);
Sleep, 200
Send, {Enter}
Sleep, 200
Send, ^l
Sleep, 200
Send, javascript:addMultiPickerItem('about','6504208',userAdded);
Sleep, 200
Send, {Enter}
Sleep, 200
Send, ^l
Sleep, 200
Send, javascript:addMultiPickerItem('about','9850638',userAdded);
Sleep, 200
Send, {Enter}
Sleep, 200
Send, ^l
Sleep, 200
Send, javascript:addMultiPickerItem('about','4520853',userAdded);
Sleep, 200
Send, {Enter}
Sleep, 200
[Mod edit: [code][/code] tags added.]

Etc. There's gotta be a better way to do this and send all these into Chrome. The only variables that will change are the numbers next to about.
example script I built for sending volume controls and play/pause to chrome for youtube.

I use this for UI automation but its supposed to be good with chrome, uiautomation: viewtopic.php?style=1&f=6&t=104999

I find python easier for stuff like chrome. Selenium is easy.
That said theirs a billion ahk-chrome libs.

https://github.com/sancarn/Small_AHK_Projects/tree/master/ChromeInjectJavascript

https://github.com/G33kDude/Chrome.ahk

Code: Select all

#NoEnv      
SetTitleMatchMode, 2

;F7 - Pause/Play
;F8 - Next Song
;F9 - 
;End - Skip Ahead on youtube or twitch
;Home - Rewind on yt or t.tv
;Alt+D or Alt+S == Video Speed Controller, Chrome Extension Hotkey, see https://github.com/igrigorik/videospeed
; ''['' or '']'' == Volume Down, Up
; Insert Key == Suspend functions.

settimer, 



~F7::
    Send {Media_Play_Pause}
return

~F8::Send    {Media_Next}
return

End::
    ControlFocus,, Google Chrome
    ControlSend,,{Right}{l}, Google Chrome
return
 
    
Home::
    ControlFocus,, Google Chrome
    ControlSend,,{Left}{j}, Google Chrome
return

!d::
    ControlFocus,, Google Chrome
    ControlSend,,{d}, Google Chrome
return

!s::
    ControlFocus,, Google Chrome
    ControlSend,,{s}, Google Chrome
return

[::   ;end == volume down
    ControlFocus,, Google Chrome
    ControlSend,,{Down}+{Down}, Google Chrome
    
return 

]::   ;end == volume down
    ControlFocus,, Google Chrome
    ControlSend,,{Up}, Google Chrome
return



Pause::Suspend
return
Ins::Suspend
return
https://github.com/samfisherirl
? /Easy-Auto-GUI-for-AHK-v2 ? /Useful-AHK-v2-Libraries-and-Classes : /Pulovers-Macro-Creator-for-AHKv2 :

Post Reply

Return to “Ask for Help (v1)”