Is there a way to automatically google cast a chrome tab or a specific website everytime I visit the website URL ?
Any command or function or script or bat file ?
Is there a way to automatically google cast a chrome tab or a specific website everytime I visit the website URL ?
Any command or function or script or bat file ?
No, you can't and even if you could, it is strongly recommended not to do that; user has to initiate the process and select a target explicitly. Here is two simple scenarios that can totally go wrong:
You need another device,
Android Mini PC MK802
Install app "autorun" and put chrome in this.
Make sure you have Chrome version 76.0.3809.132 or later. Install AutoHotkey. Make 2 files and place them on your desktop:
CastOn.ahk:
; AutoHotKey Script to start ChromeCast in Desktop Mode
;
; Declare variables
delay := 1000
; Run Chrome
Run, C:\Program Files (x86)\Google\Chrome\Application\chrome.exe --fullscreen --start-maximized
Sleep, delay
Send !f
Sleep, delay
Send c
Sleep, delay
Send {tab}{tab}
Sleep, delay
Send {Enter}
Sleep, delay
Send {Down}{Down}
Sleep, delay
Send {Enter}
Sleep, delay
Send +{tab}
Send {Enter}
Sleep, delay * 2
Send {tab}
Sleep, Delay
Send {tab}
Sleep, Delay
Send {tab}
Sleep, Delay
Send {Enter}
Sleep, delay
Send #{down} ; minimize window, casting starts
CastOff.ahk:
; AutoHotKey Script to stop ChromeCast in Desktop Mode
;
; Declare variables
delay := 1000
; Run Chrome
Run, C:\Program Files (x86)\Google\Chrome\Application\chrome.exe --fullscreen --start-maximized
Sleep, delay
Send !f
Sleep, delay
Send c
Sleep, delay
Send {tab}
Send {Enter}
Sleep, delay
Send {ESC}
Sleep, delay
Send !{f4} ; close window
Now you have 2 ahk icons on your desktop. Double clicking CastOn.ahk starts casting and leaves Chrome minimized (just wait for the magic to happen). Double clicking CastOff.ahk stops casting and closes the opened Chrome window invoked in this script.
"Sleep" is needed to avoid the simulated keystrokes to launch to early, you can however experiment with the delay variable (now set to 1000 ms, one second).
Newer versions of Chrome may lead to new UI changes in the ChromeCast functionality, which would mean this script needs to be adjusted.
Chrome may be installed in a different path as mentioned in the ahk scripts. It would not be too difficult to sort out the correct location of Chrome.exe.
If needed, you can adjust this script to cast a Chrome tab instead of the desktop or open a specific website.
Ok.. so i figured out that the interface selection is dependent upon how many chromecast devices you have. SO i put together a AutoHotkey variation of Marcel Pennock's code...
This allows you to define how many times the script needs to hit the TAB button... to select the proper casting device from the populated list crhome gives you of detected devices.
So.. if you want to cast to device 2 on your list.. you set the deviceNumber parameter to be the number of the device in the list ( 1 = first device listed.. 2 = second.. etc ).
Also.. I made it so you can select what casting mode you want... be default I set it to DESKTOP ( option 2 ).
Again.. its all about how many times you need to hit TAB to select what you want...
CastOn-1.ahk:
;------------------------------------------------------------
; AutoHotKey Script to START ChromeCast in Desktop Mode
;
; Declare variables
;
; -- Set CastMode (1=TAB 2=DESKTOP 3=FILE)
castMode := 2
deviceNumber := 1
;
delay := 1000
;------------------------------------------------------------
;------------------------------------------------------------
; Run Chrome
Run, C:\Program Files (x86)\Google\Chrome\Application\chrome.exe --fullscreen --start-maximized
;Sleep, delay
Sleep, 5000
#IfWinActive, ahk_class Chrome_WidgetWin_1
; -- SEND the ALT+F key combo to open settings
SendInput !f
Sleep, delay
; -- SEND the C key combo to select CAST
SendInput c
Sleep, delay
;------------------------------------------------------------
;------------------------------------------------------------
; -- Tab to the SOURCES drop down box and select it.
SendInput {TAB 3}
Sleep, delay
SendInput {Enter}
Sleep, delay
;------------------------------------------------------------
;------------------------------------------------------------
; -- Make your Selection ( One DOWN for TAB, Two DOWN for DESKTOP, THREE down for FILE.)
; Select DESKTOP -- TWO DOWN COMMANDS PASSED
SendInput {Down %castMode%}
Sleep, delay
SendInput {Enter}
Sleep, delay
;------------------------------------------------------------
;------------------------------------------------------------
; -- Tab OUT of the Source Selection area .. to be able to select correct device.
SendInput {TAB}
Sleep, delay
; -- Tab to the DEVICE we selected and
SendInput {TAB %deviceNumber%}
Sleep, delay
; -- START CAST.
SendInput {Enter}
Sleep, delay
;------------------------------------------------------------
;------------------------------------------------------------
; -- Minimize window, casting starts
Send {ESC}
Sleep, delay
Send #{d} ; minimize window, casting starts
;------------------------------------------------------------
CastOff-1.ahk:
;------------------------------------------------------------
; AutoHotKey Script to STOP ChromeCast in Desktop Mode
;
; Declare variables
delay := 1000
;------------------------------------------------------------
;------------------------------------------------------------
; Run Chrome
Run, C:\Program Files (x86)\Google\Chrome\Application\chrome.exe --fullscreen --start-maximized
;Sleep, delay
Sleep, 5000
#IfWinActive, ahk_class Chrome_WidgetWin_1
; -- SEND the ALT+F key combo to open settings
SendInput !f
Sleep, delay
; -- SEND the C key combo to select CAST
SendInput c
Sleep, delay
;------------------------------------------------------------
;------------------------------------------------------------
; -- Tab OUT of the Source Selection area .. to be able to select correct device.
SendInput {TAB}
Sleep, delay
; -- Tab to the DEVICE we selected and
SendInput {TAB %deviceNumber%}
Sleep, delay
; -- STOP CAST.
SendInput {Enter}
Sleep, delay
;------------------------------------------------------------
;------------------------------------------------------------
; -- CLOSE window
Send {ESC}
Sleep, delay
Send !{f4} ; close window
;------------------------------------------------------------
I also launch this directly from within a batch file... so i can call the batch file from ANY program.. it comes in handy for applications that allow you to map key or an event into a function or activity.
Example: I have StreamDeck device i use when streaming video.. i can simply map one of the streamdeck buttons.. to launch this batch file.. and bam.. one button press on the device.. and i'm autocasting to my chromecast device as well.
CAST_ONOFF_SELECT.bat gives you a menu to select turning casting on or off.
it calls the corresponding local batch file to run AutoHotkey using the proper script for that function.
CAST_ONOFF_SELECT.bat
@ECHO OFF
CLS
ECHO.
Echo Please choose a FUNCTION:
echo.
ECHO 1. Turn ON casting to DESKTOP.
ECHO 2. Turn OFF casting.
ECHO.
CHOICE /C 12 /M "Enter your choice:"
IF ERRORLEVEL 2 GOTO CastStop
IF ERRORLEVEL 1 GOTO CastStart
GOTO End
:CastStart
ECHO "STARTING CAST"
echo.
echo.
CALL %0\..\START_DESKTOP_CASTING.bat
GOTO End
:CastStop
ECHO "STOPPING CAST"
echo.
echo.
CALL %0\..\STOP_DESKTOP_CASTING.bat
GOTO End
:End
echo Process complete.
echo.
pause
START_DESKTOP_CASTING.bat
@echo off
cd "C:\Program Files\AutoHotkey" && start "CHROMECAST START" "C:\Program Files\AutoHotkey\AutoHotkey.exe" "C:\Users\Darkstar\Videos\CastON.ahk"
exit
STOP_DESKTOP_CASTING.bat
@echo off
cd "C:\Program Files\AutoHotkey" && start "CHROMECAST START" "C:\Program Files\AutoHotkey\AutoHotkey.exe" "C:\Users\Darkstar\Videos\CastOFF.ahk"
exit