Firefox Applescript

Hey everyone,

I’m trying to write an applescript which will open a certian URL in Firefox, from scratch meaning that it opens firefox and take you directly to certian url. Where I want to go use firefox to go my hotmail account, since i use Safari as my main browser but it doesn’t work well using Safari.


launch "firefox"
tell application "Firefox" to Get URL "http://www.hotmail.com"

So i made this script a application, so when i click on it it opens firefox, but it then opens a new window the url. Maybe I can use Automator for this. This is my first attempt at writing an applescripts and its not to hard to use, but getting it do something specific, is a bit more challenging. Any help wil apreciated… :slight_smile:

Thanks,

Sebastiaan

Model: intel mac
Browser: Firefox 2.0.0.3
Operating System: Mac OS X (10.4)

Hi Sebdude,

I use this script, which works quite well:

tell application “Firefox”
activate
Get URL “http://www.macosxhints.com/
Get URL “http://www.macdevcenter.com/
end tell

Of course, I’ve trimmed it a bit for you, as there are some 18 urls opened in the original (and they are all opened in tabs).

'hope this helps.

Sincerely,

VariableAsTheShade

Thanks VariableastheShade,

I’m just wondering though if it is at all possible to write a script that opens firefox but doesn’t open a unnecesary blank search page or tab. My script does pretty much the same, besided that on another computer it opens firefox and opens the link in a new window and with this computer it opens it in a new tab, which already is much better than a new window. Probably has something to do with your firefox settings… So, does anyone know how to write a script which opens firefox and sends it to hotmail… but then without opening extra tabs or windows…??? is it possible???

Sebdude

Model: Macbook 2ghz Black
Browser: Firefox 1.5.0.11 Flock/0.7.12
Operating System: Mac OS X (10.4)

Hi, Sebdude.

Firefox isn’t wonderfully scriptable itself, but you could get System Events to type keystrokes at it that achieve the same thing:

tell application "Firefox" to activate

tell application "System Events"
	keystroke "l" using {command down} -- Highlight the URL field.

	-- Insert a short delay here, if necessary.

	keystroke "http://www.hotmail.com/" & return -- Type in the URL + a return.
end tell

Addendum. If you have GUI Scripting enabled, this is slightly more bullet-proof. Again, insert delays if and where required:

tell application "Firefox" to activate

tell application "System Events"
	-- Requires GUI Scripting to be active.
	tell application process "firefox-bin"
		set frontmost to true
		-- Close any of Firefox's non-browser windows that may be in front. 
		repeat while ((count menu bar 1 each menu bar item) < 10)
			keystroke "w" using {command down}
		end repeat
		-- If there are no windows (apart from an invisible one) open a browser window.
		if ((count each window) < 2) then keystroke "n" using command down
	end tell
	-- Insert the URL into the browser window's location field.
	keystroke "l" using {command down}
	keystroke "http://www.hotmail.com/" & return
end tell

Assuming you mainly use FireFox for Hotmail, set http://www.hotmail.com as the homepage in your preferences, so when FireFox launches it opens Hotmail automatically.

Then you won’t need a script because you will only need to click the FireFox icon.

The simplest solution is usually the most elegent, but Nigel’s script does the job just like I want it to.

Thanks everyone for your help,

Sebdude

P.S. As I’ve seen with Nigel latest script, i probably use applescript even login to hotmail using certain comands, how would I go about doing that?

FYI- The “Get URL” command doesn’t seem to work in FireFox anymore, but there’s a workaround using a shell command:

http://macscripter.net/viewtopic.php?pid=127347#p127347

Hey,

I have applescript open a Pandora page which plays one of my stations in Firefox. Is there a way using applescript to close
any Pandora tabs that are open?

Thanks,

Carl