Grabbing current tab from Firefox

I like Firefox and it is my default browser. I also often need to capture a link of the current tab. I have an extension that will make a markdown link of one tab, selected tabs or all tabs, and it is great for the latter two, but a pain if I want only the current tab.

Is there anyway to automate getting the url in the current tab?

Or, better yet, automating the mouse click on the extension and then choosing the first menu option?


I’ve used this script successfully for grabbing the Firefox URL and pasting it in the current application. I did not write this, but I found this somewhere else (can’t remember where)

use scripting additions
use framework "Foundation"

tell application "System Events" to set activeApp to name of first application process whose frontmost is true

tell application "Firefox" to activate

set thePasteboard to current application's NSPasteboard's generalPasteboard()
set theCount to thePasteboard's changeCount()

-- send cmd+l and cmd+c keystrokes to FF to highlight and copy the URL
tell application "System Events"
	keystroke "l" using {command down}
	delay 0.2
	keystroke "c" using {command down}
end tell

-- wait for the clipboard content change to have been detected
repeat 20 times
	if thePasteboard's changeCount() is not theCount then exit repeat
	delay 0.1
end repeat

-- get the clipboard contents
set the_url to the clipboard

tell application activeApp to activate

delay 0.5

return the_url as text

Thank you very much. I’ll try and build something from that.

I know you didn’t write the script, but it is the probably the most pointless use of the Objective-C bridge ever, all just to do with the NSPasteboard what is just as easily done with the scripting additions clipboard (which ends up being used to get url).

Has anyone thought about finding the .savedState file or any other file that Firefox must write to in order to restore tabs after a crash?