I ran into the same problem myself, so I made a new program that uses some brute-force DDE code I hacked from somewhere else in this forum to make sure the DDE is directed to the most recently active instance of Firefox. I use it all the time, and it seems to work mostly OK.
This script can be called from another script with RunWait, and then the results are read from an INI file.
Code:
;=============================================================================================================
;This reprieves the URL and Title of the page currently displayed in the most recently active instance of
;Firefox. It uses DDE to read the data, and then writes the results into an INI file.
;
;Results are written to %Temp%\BrowserInfo.ini in the following form:
; [Global]
; Address=http://www.autohotkey.com/forum/viewtopic.php?p=381624#381624
; Title=Retrieve AddressBar of Firefox through DDE Message
; Link=<a href="http://www.autohotkey.com/forum/viewtopic.php?p=381624#381624">Retrieve AddressBar of Firefox through DDE Message</a>
;
; For details, read the post at the address shown above.
;-------------------------------------------------------------------------------------------------------------
sApplication := "firefox" ; iexplore, opera
sTopic := "WWW_GetWindowInfo"
sItem := "0xFFFFFFFF"
Noise := "Free source code and programming help"
CF_TEXT := 1
WM_DDE_INITIATE := 0x3E0
WM_DDE_TERMINATE := 0x3E1
WM_DDE_ADVISE := 0x3E2
WM_DDE_UNADVISE := 0x3E3
WM_DDE_ACK := 0x3E4
WM_DDE_DATA := 0x3E5
WM_DDE_REQUEST := 0x3E6
WM_DDE_POKE := 0x3E7
WM_DDE_EXECUTE := 0x3E8
DetectHiddenWindows, On
OnMessage(WM_DDE_ACK , "DDE_ACK")
OnMessage(WM_DDE_DATA, "DDE_DATA")
nAppli := DllCall("GlobalAddAtom", "str", sApplication, "Ushort")
nTopic := DllCall("GlobalAddAtom", "str", sTopic , "Ushort")
Process, Exist
WinGet, hAHK, ID, ahk_pid %ErrorLevel%
SendMessage, WM_DDE_INITIATE, hAHK, nAppli | nTopic << 16,, ahk_id 0xFFFF
DllCall("GlobalDeleteAtom", "Ushort", nAppli)
DllCall("GlobalDeleteAtom", "Ushort", nTopic)
Return
DDE_ACK(wParam, lParam, MsgID, hWnd) {
Global sItem, CF_TEXT, WM_DDE_REQUEST
nItem := DllCall("GlobalAddAtom", "str", sItem, "Ushort")
PostMessage, WM_DDE_REQUEST, hWnd, CF_TEXT | nItem << 16,, ahk_id %wParam%
If ErrorLevel
DllCall("GlobalDeleteAtom", "Ushort", nItem)
}
DDE_DATA(wParam, lParam, MsgID) {
Global
DllCall("UnpackDDElParam", "Uint", MsgID, "Uint", lParam, "UintP", hData, "UintP", nItem)
DllCall( "FreeDDElParam", "Uint", MsgID, "Uint", lParam)
pData := DllCall("GlobalLock", "Uint", hData)
VarSetCapacity(sInfo, DllCall("lstrlen", "Uint", pData+4))
DllCall("lstrcpy", "str", sInfo, "Uint", pData+4)
DllCall("GlobalUnlock", "Uint", hData)
If (*(pData+1) & 0x20)
DllCall("GlobalFree", "Uint", hData)
If (*(pData+1) & 0x80)
PostMessage, WM_DDE_ACK, hWnd, 0x80 << 8 | nItem << 16,, ahk_id %wParam%
Loop, Parse, sInfo, CSV
{
if(A_Index == 1) {
Address := A_LoopField
IniWrite %A_LoopField%, C:\Temp\BrowserInfo.ini,Global,Address
}
else if(A_Index == 2) {
Title := A_LoopField
IniWrite %A_LoopField%, C:\Temp\BrowserInfo.ini,Global,Title
}
}
GSub(Title, " - Opera$", "")
GSub(Title, "\x22" , "'")
GSub(Title, Noise , "")
Link := "<a href=""" . Address . """>" . Title "</a>"
EnvGet Temp, Temp
IniWrite %Link%, %Temp%\BrowserInfo.ini,Global,Link
ExitApp
}
DDE_POKE(sItem, sData) {
Global WM_DDE_POKE, hWndClient, hWndServer
If SubStr(sData, -1) <> "`r`n"
sData .= "`r`n"
hItem := DllCall("GlobalAddAtom", "str", sItem, "Ushort")
hData := DllCall("GlobalAlloc", "Uint", 0x0002, "Uint", 2+2+StrLen(sData)+1) ; GMEM_MOVEABLE
pData := DllCall("GlobalLock" , "Uint", hData)
DllCall("ntdll\RtlFillMemoryUlong", "Uint", pData, "Uint", 4, "Uint", 1<<13|1<<14|1<<16) ; bRelease, CF_TEXT
DllCall("lstrcpy", "Uint", pData+4, "Uint",&sData)
DllCall("GlobalUnlock", "Uint", hData)
lParam := DllCall("PackDDElParam", "Uint", WM_DDE_POKE, "Uint", hData, "Uint", hItem)
PostMessage, WM_DDE_POKE, hWndClient, lParam,, ahk_id %hWndServer%
If ErrorLevel
{
DllCall("GlobalFree", "Uint" , hData)
DllCall("GlobalDeleteAtom", "Ushort", hItem)
DllCall("FreeDDElParam", "Uint", WM_DDE_POKE, "Uint", lParam)
}
}
DDE_EXECUTE(sCmd) {
Global WM_DDE_EXECUTE, hWndClient, hWndServer
hCmd := DllCall("GlobalAlloc", "Uint", 0x0002, "Uint", StrLen(sCmd)+1)
pCmd := DllCall("GlobalLock" , "Uint", hCmd)
DllCall("lstrcpy", "Uint", pCmd, "str",sCmd)
DllCall("GlobalUnlock", "Uint", hCmd)
PostMessage, WM_DDE_EXECUTE, hWndClient, hCmd,, ahk_id %hWndServer%
If ErrorLevel
DllCall("GlobalFree", "Uint", hCmd)
}
;-------------------------------------------------------------------------------------------------------------
GSub(byref Haystack, Needle, Replacement) {
Haystack := RegexReplace(Haystack, Needle, Replacement)
return Haystack
}
I use this all the time with another script that grabs this information, filters it down, there's a bunch of other processing, and then generates an e-mail with a hyperlink to the page. I have various hotkeys that filter the data differently, or send it to different people, etc.
Note that if all you want to do is send a link to the current page via e-mail, there are easier ways to do it. The easiest way is using a small Bookmarklet. That's what I do on my iPad where I don't have access to AHK (which practically cripples me). Make a bookmark with this text:
Code:
javascript:(function(){location.href='mailto:?SUBJECT=Link: ' + document.title + '&BODY=<html><body><a href=\x27' + escape(location.href) + '\x27>' + document.title + '</a></body></html>';})()
or look
http://www.freewaregenius.com/2009/02/05/email-this-a-bookmarklet-that-can-email-any-page-from-any-browser/ or
http://www.bing.com/search?q=email+bookmarklet