Hello, my default and preferred browser is Chrome, but sometimes I would like to open the URL of the current Chrome tab in Firefox.
Is that possible using AHK?
Thank you
Open Chrome tab in Firefox? Topic is solved
-
- Posts: 5
- Joined: 31 Dec 2019, 14:57
Re: Open Chrome tab in Firefox? Topic is solved
Code: Select all
#Requires AutoHotkey v2.0
#HotIf WinActive('ahk_exe chrome.exe')
^F5::Run('firefox.exe ' getUrl()), SoundBeep(1500)
#HotIf
getUrl() { ; Get URL of the active Web browser window
; Adapted: https://gist.github.com/7cce378c9dfdaf733cb3ca6df345b140
Static TreeScope_Descendants := 4
, UIA_ControlTypePropertyId := 30003
, UIA_DocumentControlTypeId := 50030
, UIA_EditControlTypeId := 50004
, UIA_ValueValuePropertyId := 30045
IUIAutomation := ComObject('{FF48DBA4-60EF-4201-AA87-54103EEF594E}'
, '{30CBE57D-D9D0-452A-AB13-7AC5AC4825EE}')
eRoot := ComValue(13, 0)
If HRESULT := ComCall(6, IUIAutomation, 'Ptr', WinGetID('A'), 'Ptr*', eRoot)
Throw Error('IUIAutomation::ElementFromHandle()', -1, HRESULT)
ctrlTypeId := WinGetClass('A') ~= 'Chrome' ? UIA_DocumentControlTypeId : UIA_EditControlTypeId
value := Buffer(8 + 2 * A_PtrSize, 0)
NumPut('UShort', 3, value, 0), NumPut('Ptr', ctrlTypeId, value, 8)
condition := ComValue(13, 0)
If HRESULT := A_PtrSize = 8
? ComCall(23, IUIAutomation, 'UInt', UIA_ControlTypePropertyId, 'Ptr', value, 'Ptr*', condition)
: ComCall(23, IUIAutomation, 'UInt', UIA_ControlTypePropertyId
, 'UInt64', NumGet(value, 0, 'UInt64')
, 'UInt64', NumGet(value, 8, 'UInt64')
, 'Ptr*' , condition
)
Throw Error('IUIAutomation::CreatePropertyCondition()', -1, HRESULT)
eFirst := ComValue(13, 0)
If HRESULT := ComCall(5, eRoot, 'UInt', TreeScope_Descendants, 'Ptr', condition, 'Ptr*', eFirst)
Throw Error('IUIAutomationElement::GetRootElement()', -1, HRESULT)
propertyValue := Buffer(8 + 2 * A_PtrSize)
If HRESULT := ComCall(10, eFirst, 'UInt', UIA_ValueValuePropertyId, 'Ptr', propertyValue)
Throw Error('IUIAutomationElement::GetCurrentPropertyValue()', -1, HRESULT)
ObjRelease(eFirst.Ptr), ObjRelease(eRoot.Ptr)
Try {
pProperty := NumGet(propertyValue, 8, 'Ptr')
Return StrGet(pProperty, 'UTF-16')
}
}
-
- Posts: 5
- Joined: 31 Dec 2019, 14:57
Re: Open Chrome tab in Firefox?
Thank you @mikeyww unfortunately that hasn't worked for me; the code runs in the background but pressing the hotkey doesn't open Firefox. I've tried explicitly quoting the full path to the firefox.exe and changing the hotkey, but to no avail.mikeyww wrote: ↑29 Apr 2024, 16:55Code: Select all
#Requires AutoHotkey v2.0 #HotIf WinActive('ahk_exe chrome.exe') ^F5::Run('firefox.exe ' getUrl()), SoundBeep(1500) #HotIf getUrl() { ; Get URL of the active Web browser window ; Adapted: https://gist.github.com/7cce378c9dfdaf733cb3ca6df345b140 Static TreeScope_Descendants := 4 , UIA_ControlTypePropertyId := 30003 , UIA_DocumentControlTypeId := 50030 , UIA_EditControlTypeId := 50004 , UIA_ValueValuePropertyId := 30045 IUIAutomation := ComObject('{FF48DBA4-60EF-4201-AA87-54103EEF594E}' , '{30CBE57D-D9D0-452A-AB13-7AC5AC4825EE}') eRoot := ComValue(13, 0) If HRESULT := ComCall(6, IUIAutomation, 'Ptr', WinGetID('A'), 'Ptr*', eRoot) Throw Error('IUIAutomation::ElementFromHandle()', -1, HRESULT) ctrlTypeId := WinGetClass('A') ~= 'Chrome' ? UIA_DocumentControlTypeId : UIA_EditControlTypeId value := Buffer(8 + 2 * A_PtrSize, 0) NumPut('UShort', 3, value, 0), NumPut('Ptr', ctrlTypeId, value, 8) condition := ComValue(13, 0) If HRESULT := A_PtrSize = 8 ? ComCall(23, IUIAutomation, 'UInt', UIA_ControlTypePropertyId, 'Ptr', value, 'Ptr*', condition) : ComCall(23, IUIAutomation, 'UInt', UIA_ControlTypePropertyId , 'UInt64', NumGet(value, 0, 'UInt64') , 'UInt64', NumGet(value, 8, 'UInt64') , 'Ptr*' , condition ) Throw Error('IUIAutomation::CreatePropertyCondition()', -1, HRESULT) eFirst := ComValue(13, 0) If HRESULT := ComCall(5, eRoot, 'UInt', TreeScope_Descendants, 'Ptr', condition, 'Ptr*', eFirst) Throw Error('IUIAutomationElement::GetRootElement()', -1, HRESULT) propertyValue := Buffer(8 + 2 * A_PtrSize) If HRESULT := ComCall(10, eFirst, 'UInt', UIA_ValueValuePropertyId, 'Ptr', propertyValue) Throw Error('IUIAutomationElement::GetCurrentPropertyValue()', -1, HRESULT) ObjRelease(eFirst.Ptr), ObjRelease(eRoot.Ptr) Try { pProperty := NumGet(propertyValue, 8, 'Ptr') Return StrGet(pProperty, 'UTF-16') } }
Re: Open Chrome tab in Firefox?
Do you hear a beep when you press Ctrl+F5 ? You are pressing the Ctrl key along with F5, right? And you don’t get an error saying that the file is not found? What exactly happens when you press the hotkey? Nothing at all?
-
- Posts: 5
- Joined: 31 Dec 2019, 14:57
Re: Open Chrome tab in Firefox?
I'm an idiot! I wasn't holding down CTRL .... thank you both; it's working perfectly now I'm pressing the right buttons!
Who is online
Users browsing this forum: Bing [Bot] and 28 guests