firefox refresh applescript

I have the need for having two different browsers open at the same
time to a specific page and having the page on each refresh regularly.
I have the applescript for Safari and Internet Explorer, but would
like to use Firefox instead of IE. The Safari and IE scripts are
available as a freeware download on Version Tracker, but I have been
unable to find one for Firefox. I have contacted the writer of them,
but he is not responding. Can anyone help? I would be very
appreciative, thank you in advance.

iMac G5 and iBook G4, Mac OS X (10.5.1)

Posted on Nov 20, 2007 9:59 AM

Reply
28 replies

Nov 20, 2007 11:30 AM in response to Peggy Guelle

Hello

If next code reloads the front window of Firefox, then there's hope to adjust it for your needs.
If not, that's it. As far as I know, Firefox's AppleScript support is very little.

-- SCRIPT
tell application "Firefox"
set u to get «class curl» of window 1
«event GURLGURL» u given «class HWIN»:window 1
end
-- END OF SCRIPT

Here I used AppleScript raw code because I've heard that, e.g., 'get URL of window 1' cannot be complied with Firefox but 'get «class curl» of window 1' can be actually executed.

Good luck,
H



PS. If «event GURLGURL» is compiled as 'open location' and that lets the script fail, try something as follows.

-- SCRIPT1
run script "tell application \"Firefox\"
set u to get «class curl» of window 1
«event GURLGURL» u given «class HWIN»:window 1
end"
-- END OF SCRIPT1



PPS. The codes above are derived from the following one, which reloads the front window of WamCom 1.3.1 (refined Mozilla 1.3.1) under OS9.1 at hand.

-- PROTOTYPE
tell application "Mozilla"
set u to get URL of window 1
GetURL u inside window 1
end tell
-- END OF PROTOTYPE

Nov 20, 2007 5:26 PM in response to Peggy Guelle

Hello Peggy Guelle,

It is quite easy to run and test the provided code. Here's the recipe.

(1) Launch Script Editor.app, which is located at (probably):

/Application/AppleScript/Script Editor.app

(2) Copy the provided code (from '-- SCRIPT' to '-- END OF SCRIPT') in this page and paste it into a new window of Script Editor.

(3) Press compile button (one with hammer icon).

(4) Make sure Firefox is running and has at least one window is loaded with a web page. E.g., www.apple.com page is loaded into its front window.

(5) Run the script by pressing run button in the Script Editor's window and see what happens in Firefox's front window.

If the front window of Firefox is reloaded, the script is working as intended and I can modified the code to suit your needs (e.g. to reload the page every 2 minutes etc.)
So please post back with the result.

(I use neither OSX nor Firefox, so I cannot test it by myself. Sorry for that.)
Kind regards,
H

Nov 21, 2007 11:58 AM in response to Peggy Guelle

To view the actual AppleScript source code of either 'Safari_Refresh' and / or 'IE_Refresh' ...

01. Open the '/Applications/AppleScript/' folder.
02. Drag either the 'Safari_Refresh' and / or 'IE_Refresh' applet(s) onto 'Script Editor'.

At this point you can view, and even edit, the source code of the dragged applets.
Therefore, there is not need to contact the author of the applets, for any support.

Note: AppleScript source code saved as an application, is called an applet.

Nov 21, 2007 12:37 PM in response to Peggy Guelle

Now that you know where 'Script Editor' is, here is some basic source code, to start with, ...

01. Launch 'Script Editor'.
02. Copy the AppleScript source code below, between the lines of -- Code starts here --' and '-- Code ends here -- '

-- Code starts here --

property tDelay : 180
property tURL : "http://www.apple.com"

on idle
tell application "Firefox" to Get URL tURL
return tDelay
end idle

on run
set tURL to (text returned) of (display dialog "Enter a URL:" default answer tURL default button "OK")
tell application "Firefox" to OpenURL tURL
end run

-- Code ends here --

03. Paste the, above copied, contents - into a new editor window ('Script Editor', 'File, New' menu item, or 'Command n').
04. Save the source code - 'Script Editor', 'File, Save' menu item, or 'Command s'. A drop down sheet will appear.
05. Enter the desired applet name into the 'Save As:' textedit field.
06. Select the applets destination folder.
07. From the 'File Format:' popup menu - select the 'Application' menu item.
08. Click on the 'Options:' 'Stay Open' check box, to add a check mark.
09. Click on the 'Save' button; or, press the <return> or <enter> key.

Nov 22, 2007 6:49 AM in response to Peggy Guelle

Hello Peggy Guelle,

Well, not that I got your report... ;- )
Here's some untested code you may try, which is intended to behave in similar way to the IE_Refresh or Safari_Refresh you mentioned in a reply to dev_sleidy.

Copy this code (from '-- SCRIPT' to '-- END OF SCRIPT') into a new window of Script Editor and save it as Stay-open applet (by saving it as application with checking 'stay-open' check box and unchecking some 'show start up screen' check box in 'save' dialogue). Then double click the resulting applet when 'Firefox' is running and showing some web page(s).

Note that if «event GURLGURL» etc is compiled as other text (such as 'GetURL' etc) in compiling the source code, then leave them alone as compiled. I used raw code (notation as «...») just in case Firefox doesn't provide sufficient AppleScript dictionary. If it is compiled as 'GetURL' etc, it means Firefox does have AppleScript dictionary entry for «event GURLGURL», which would be better!

Good luck,
H



-- SCRIPT
(*
reload Firefox's windows
v0.1

Every intvl seconds, this script will
- reload the front window if there's only one window open; or
- reload the windows except the front window if there're more than one window open.

Usage -
Save this script as stay-open applet.
Run it and it will ask you the reload interval in seconds.
Once the interval is set, it will reload the window(s) periodiacally by the given interval.

*)
property intvl : 180 -- [sec]
property mss1 : "Please enter the refresh time in seconds."
property errs1 : "Invalid data for refresh time. Please re-enter."
property btt1 : {"Cancel", "OK"}

on run
init()
--reload()
end run

on idle
reload()
return intvl
end idle

on reload()
tell application "Firefox"
set kx to count windows
if kx > 1 then
set k1 to 2
else
set k1 to 1
end if
repeat with k from k1 to kx
try
set u to get «class curl» of window k
«event GURLGURL» u given «class HWIN»:window k
--set u to get URL of window k
--GetURL u inside window k
on error --
end try
end repeat
end tell
end reload

on init()
repeat
set ddr to (display dialog mss1 default answer intvl ¬
buttons btt1 default button 2 with icon 1 giving up after 30)
if gave up of ddr then
set intvl to 180
exit repeat
else
try
set intvl to text returned of ddr as integer
exit repeat
on error --
display dialog errs1 with icon 2
end try
end if
end repeat
end init
-- END OF SCRIPT



Message was edited by: Hiroto

Nov 22, 2007 7:15 AM in response to Peggy Guelle

Hello Peggy Guelle,

My pleasure. Glad to hear it works!

Because of the timing of your last post and my last edit, I'm afraid you may have missed the fix in the script. I've fixed the code in init() handler. (Added 'exit repeat' statement after 'set intvl to 180' line in 'if gave up of ddr then' block) So if your copied script has no 'exit repeat' there, then please replace your source code with the current one.

One more thing about the script. It won't restore the scrolling position when reloading the page. I cannot think of any work-around for this issue for now.

All the best,
Hiroto

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

firefox refresh applescript

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.