Jump to content


Photo

Grab Current URL From Firefox


  • Please log in to reply
17 replies to this topic

#1 godsstigma

godsstigma
  • Members
  • 222 posts

Posted 08 December 2009 - 03:20 AM

I am working on an auto-stumble script for a couple people and have an issue with grabbing the current URL address in Firefox.

Right now I am just sending F6 to highlight the address bar and collect that text, but this is very inefficient and can produce issues if the caret is already in the address or search bar.
Firefox does not display any kind of control text I can grab either.

I need these URLs to put into a database of recent stumbles and Stumble Upon doesn't offer an API of any sort, so I am a bit lost.

Does anyone have any ideas?

#2 Lexikos-nli

Lexikos-nli
  • Guests

Posted 08 December 2009 - 03:37 AM

You could try the MozRepl extension. See Remotely control Firefox, or more specifically my example.

#3 jethrow

jethrow
  • Fellows
  • 2549 posts

Posted 08 December 2009 - 05:12 AM

Based on this thread.

This seems to work for me. I'm using a portable copy of firefox - not sure if that will make a difference or not:
SessionStorePath := "" ; enter sessionstore.js FileName

WinGetTitle, WinTitle, ahk_class MozillaUIWindowClass
StringReplace, WinTitle, WinTitle, % " - Mozilla Firefox"
needle = "url":"([^"]*?)","title":"%WinTitle%

FileRead, data, %SessionStorePath%
RegExMatch(data,needle,match)
MsgBox, %match1%
The path to the sessionstore.js file should be something like: %A_AppData%\Mozilla\Firefox\Profile\your profile name\sessionstore.js

#4 SoLong&Thx4AllTheFish

SoLong&Thx4AllTheFish
  • Members
  • 4999 posts

Posted 08 December 2009 - 07:44 AM

I've been using Seans' method for a long time:
Retrieve AddressBar of Firefox through DDE Message
<!-- m -->http://www.autohotke...ic19169-15.html<!-- m -->

#5 Believer

Believer
  • Members
  • 41 posts

Posted 08 December 2009 - 01:16 PM

I wrote something similar a while ago, and used ctrl+l (control plus L) to highlight the address bar URL, seemed to be very effective and stable ... and simple.

#6 Hasso

Hasso
  • Members
  • 324 posts

Posted 08 December 2009 - 02:00 PM

I wrote something similar a while ago, and used ctrl+l (control plus L) to highlight the address bar URL, seemed to be very effective and stable ... and simple.

F6 and Alt+s work as well...

#7 godsstigma

godsstigma
  • Members
  • 222 posts

Posted 08 December 2009 - 11:07 PM

Thanks guys!!

Based on this thread.

This seems to work for me. I'm using a portable copy of firefox - not sure if that will make a difference or not:

SessionStorePath := "" ; enter sessionstore.js FileName

WinGetTitle, WinTitle, ahk_class MozillaUIWindowClass
StringReplace, WinTitle, WinTitle, % " - Mozilla Firefox"
needle = "url":"([^"]*?)","title":"%WinTitle%

FileRead, data, %SessionStorePath%
RegExMatch(data,needle,match)
MsgBox, %match1%
The path to the sessionstore.js file should be something like: %A_AppData%\Mozilla\Firefox\Profile\your profile name\sessionstore.js


Jethrow - This is very very cool. I had no idea that Firefox kept this data.
The only problem with reading the sessionrestore.js file is that Firefox waits about 1 second AFTER the page is fully loaded to write to this file, which is not a huge problem.

Lexikos - I haven't had time to check this out yet, it will take me a minute to wrap my head around what you are doing. but it seems like some very cool stuff as well as hugov's suggestion of using DDE.

Thanks everyone for their valued and highly appreciated help.
This is why i keep coming back to AHK.

#8 chris966

chris966
  • Guests

Posted 23 December 2009 - 11:59 AM

I've been using Seans' method for a long time:
Retrieve AddressBar of Firefox through DDE Message
http://www.autohotke...ic19169-15.html

thats interesting - how exactly do you use it though? doesn't really make sense to me

#9 SoLong&Thx4AllTheFish

SoLong&Thx4AllTheFish
  • Members
  • 4999 posts

Posted 23 December 2009 - 12:05 PM

Download <!-- m -->http://www.autohotke...Scripts/DDE.zip<!-- m -->
and simply run DDEMessage.ahk

You could create a function for, make a label and #include it in your script it or simply run the Script
run DDEMessage.ahk
and it will place title & url on the clipboard for further processing, by adopting the script you can have the title or url only. Works with FF, IE and Opera as far as I know.

#10 Gauss

Gauss
  • Members
  • 203 posts

Posted 05 February 2010 - 09:03 PM

Download <!-- m -->http://www.autohotke...Scripts/DDE.zip<!-- m -->
and simply run DDEMessage.ahk

You could create a function for, make a label and #include it in your script it or simply run the Script

run DDEMessage.ahk
and it will place title & url on the clipboard for further processing, by adopting the script you can have the title or url only. Works with FF, IE and Opera as far as I know.


How can I get the URL only? no "s and no title

#11 SoLong&Thx4AllTheFish

SoLong&Thx4AllTheFish
  • Members
  • 4999 posts

Posted 05 February 2010 - 09:20 PM

How can I get the URL only? no "s and no title

Don't have the files at hand but look at the sData or sInfo or clipboard variable they contain the url & title. You can simply stringtrim, substr or stringsplit? etc to get either the url or the title

#12 Gauss

Gauss
  • Members
  • 203 posts

Posted 05 February 2010 - 09:54 PM

How can I get the URL only? no "s and no title

Don't have the files at hand but look at the sData or sInfo or clipboard variable they contain the url & title. You can simply stringtrim, substr or stringsplit? etc to get either the url or the title


How do I get what is between the first 2 ""?
So insteend of this:
"http://www.google.com/intl/en/","Google",""
this:
<!-- m -->http://www.google.com/intl/en/<!-- m -->

#13 Tuncay

Tuncay
  • Members
  • 1943 posts

Posted 05 February 2010 - 10:00 PM

How do I get what is between the first 2 ""?
So insteend of this:
"http://www.google.com/intl/en/","Google",""
this:
<!-- m -->http://www.google.com/intl/en/<!-- m -->

Look at this:
list = "http://www.google.com/intl/en/","Google","" 
Loop, Parse, list, CSV
    MsgBox %A_LoopField%


#14 Gauss

Gauss
  • Members
  • 203 posts

Posted 05 February 2010 - 10:12 PM

Look at this:

list = "http://www.google.com/intl/en/","Google","" 
Loop, Parse, list, CSV
    MsgBox %A_LoopField%


Hmm..
Why is it so difficult :?
I just want the URL and not the title

I added yours like this:

Clipboard := % sData
list = %Clipboard%
Loop, Parse, list, CSV
MsgBox %A_LoopField%

But then I get 3 msg boxes, url, title and an empty one!

And all I want is to have the url on the clipboard

I believe there is a way to even edit DDEML.ahk itself so it returns with that only, I just don't know how

#15 SoLong&Thx4AllTheFish

SoLong&Thx4AllTheFish
  • Members
  • 4999 posts

Posted 05 February 2010 - 10:24 PM

Here are three methods, pretty basic stuff, read up on strings !
clipboard="http://www.google.com/intl/en/","Google","" 
;method one
url1:=substr(clipboard,instr(clipboard,Chr(34))+1,instr(clipboard,Chr(34),false,2)-2)
MsgBox % Url1 
;method two
Loop, parse, clipboard, csv
	{
	 url2:=A_LoopField
	 Break
	} 
MsgBox % Url2
;method three
StringSplit, url3, clipboard, `,
MsgBox % Url31 ; still need to trim "
StringTrimLeft, Url31, Url31, 1
StringTrimRight, Url31, Url31, 1
MsgBox % Url31 ; correct
You could also use RegExReplace and a number of other methods I'm sure.