GUIscripting vis-a-vis Firefox (Menu Mining)

Greetings to everyone. Thanks for having this forum.

I’m attempting exactly my second applescript.

The endgame is to have an applescript export my firefox bookmarks (via firefox’s “export” command) to a file and then upload it into a webpage on my server. I’m using a G4, firefox 1.0.4, and OS 10.3.9 (Panther). So I am, at this point, just trying to get my applescript to open the “Bookmarks Manager” window. I figure once I can do that, I’ll be able to similarly perform the export menu item from that window.

I understand that I could just go “get” the bookmarks file, but, like many others on this forum, I’m using this as a menu-mining exercise. :slight_smile:

I’ve searched these fora and uncovered many pitfalls and I believe I’ve avoided them. I’ve enabled assistive devices and and confirmed (via both the online script at apple.com and the pre-loaded “probe menu bar” script) that gui scripting is “on”. I’m using an elipsis instead of three-dots, etc.

Here is the script:

tell application "Firefox"
	activate
end tell
on do_menu(firefox, bookmarks, "Manage Bookmarks.")
	try
		tell application "System Events"
			tell application process firefox
				set frontmost to true
				delay 2
				tell process firefox
					tell menu bar 1
						tell menu bar item 7
							click menu item 2 of menu 1
						end tell
					end tell
				end tell
			end tell
		end tell
		return true
	on error error_messsage
		return false
	end try
end do_menu

Here are my questions:
When I run this, it executes without an error…but nothing happens. That is, no Bookmarks Manager window opens. I get the impression that it is somehow open in the background without me seeing it, but I don’t have the debugging expertise with applescript to verify that. For example, I don’t see a “visible” attribute in UI Element Instpector for that element or anything like that (the “AXVisibleChildren” doesn’t seem salient). How would a more experienced applesdev’er go about debugging a script that has no visible result (with an emphasis on this specific example, obviously)?

You’ll notice that I departed from apple.com’s example by putting the first three lines (the activation of firefox) outside the do_menu routine. When it was inside that routine, it didn’t activate at all. Lines 7 and 8 are designed to make sure the Firefox is frontmost and that seems to work. Why was it necessary to do both? All examples that I’ve seen do one or the other.

I’ve tried “perform action “AXPick” of” and “perform action “AXPress” of” instead of “click” and the result (or lack thereof) seems the same. Does that matter?

I honestly don’t understand the significance of lines 19-21…my earlier versions of the script returned error messages even without those lines being present. Pardon my newbieness on that point, but I’m curious.

Finally, I understand that Firefox is not at all applescript friendly, but I was surprised by the lack of firefox related guiscripts. I remain undaunted, but is there something uniquely un-guiscript about Firefox that I’m unaware of? System Events on the os should bypass all of that, I would think.

Thanks for your help!

:-{)]

Mark A. Morenz, MS Ed., CCAI, Linux+

“Not all of this is true” --Steven Wright

Hi Mark,

your script can’t work. You activate the app “Firefox” and then you define a handler (subroutine),
but you don’t call it.

Firefox is a special case to script the GUI. Unlike other applications the process is called “firefox-bin” not “Firefox”.
Here is a working example. I commented out the handler definition and the return lines

activate application "Firefox"
-- on do_menu(firefox, bookmarks, "Manage Bookmarks.")
try
	tell application "System Events"
		tell process "firefox-bin"
			click menu item 4 of menu 1 of menu bar item 7 of menu bar 1
		end tell
	end tell
	-- return true
on error e
	-- return false
	display dialog e
end try
-- end do_menu

With a handler, it could be like this (this works only on a english system).
I couldn’t test it, my copy of Firefox is german :wink:

activate application "Firefox"
do_menu("firefox-bin", "bookmarks", "Manage Bookmarks.")

on do_menu(proc, theMenu, theMenuItem)
	try
		tell application "System Events"
			tell process proc
				click menu item theMenuItem of menu 1 of menu bar item theMenu of menu bar 1
			end tell
		end tell
		return true
	on error
		return false
	end try
end do_menu

Hi Mark,

I can’t exactly replicate your environment, but this does what you are trying to achieve in mine (OS X 10.4.10 / Firefox 2.0.0.4)

do_menu("Firefox", "Organize Bookmarks...", "Bookmarks")

on do_menu(_app, _mItem, _mbItem)
	activate application _app
	tell application "System Events"
		tell process _app
			click menu item _mItem of menu 1 of menu bar item _mbItem of menu bar 1
		end tell
	end tell
end do_menu

Grr always beating me to the punch Stefan =)

Anyways I’m curious what version of Firefox you are using because as I did in my version I can refer to the process as “Firefox” without any problems… That is also how UI Browser is reading the process.

I’m sorry (like always ;))

I’m not really using Firefox, I perfer Safari also because of its better scripting capability.
My FF-Version is 2.0.0.1 german, I discovered once that the name of the process in System Events is different, so I use “firefox-bin”.
I’ve never tried just “Firefox”

Hmm interesting… I wonder if thats only on non-english systems… ::ponders::

My thanks to everyone! The speed and quality of the replies was excellent…this forum was as good as advertised. :slight_smile:

With the addition of the “frontmost” line, the example without the handler worked perfectly:

try
	tell application "System Events"
		tell process "Firefox-bin"
			set frontmost to true
			click menu item 2 of menu 1 of menu bar item 7 of menu bar 1
		end tell
	end tell
on error e
	display dialog e
end try

firefox-bin did turn out to be the correct process name.

Just for my own edification I’ll spend a little time tweaking the examples with handlers to try and get them to work. I keep getting “NSReceiverEvaluationScriptError: 4” …at first I thought it was a mismatched parameter name but that wasn’t it.

Anyway, I can move forward. I hope you won’t be disappointed if I post Qs on any other bumps in the road, though. Thanks again!

:-{)]

-MM

Ah, it turned out that the script was only working when Firefox was already on…

I added a few lines and now it seems to work in either event. I know that I should really do some sort of “if…else” construct for this, but I’m in a hurry. OH, and note the delay…that turned out to be necessary to allow Firefox to get up and running. GUIscripting is fascinating…

--This program (which will be operated by cron job on my G4) is designed to upload my Firefox bookmarks to my website so that they will be universally accessible.
--This first part just makes sure Firefox is active and foremost and then turns on the bookmark mananger
tell application "Firefox" to activate
delay 8
try
	tell application "System Events"
		tell process "Firefox-bin"
			set frontmost to true
			click menu item 2 of menu 1 of menu bar item 7 of menu bar 1
		end tell
	end tell
on error e
	display dialog e
end try
--more to come
end

Be well!

:-{)]

-MM

In browsing through this site for information on scripting FireFox, I came across this thread. It seemed like what mmorenz was tyrying to do was what I wanted to do except that I wanted to click on one of the toolbar buttons. So I copied the script shown by mmorenz on 2007-6-27 at 1:29:37 PM. But when I run this script I get an applescript error : Process Not Found. Anu suggestions? Thanks.

Hi,

the names of the processes are case sensitive. Try “firefox-bin” (btw: the 8 seconds delay is actually not needed)

PS: the scriptability of FireFox is hopeless (even GUI scripting). E.g. it’s not possible to access toolbar buttons

OK, thanks. I didn’t realize you couldn’t access the toolbar buttons.