Does anyone know how to script firefox to create a web archive? I’ve recently seitched to Firefox so that I could use the extension “Bookmark Synchronizer” and my .Mac account to keep all of my bookmarks at work and home synchronized. But at home (on a mac) I like to capture web archives to DTP. What is a Firefox user to do? Would it be possible to script DevonAgent to read and write a Firefox bookmark file (xbel file), because that might also work. Thanks.
The last time I launched Firefox this application didn’t support scripting at all. If it should be possible to get the URL now, then you could use the “download web archive” command of DT Pro.
tell application "Firefox"
set myFirefox to properties of front window
end tell
the result is:
having no applescript skills at all - i dont know how to get «class curl» out of this - but i imagine it must be possible
Louise.
Even the latest release doesn’t support AppleScript (only the “Get URL” command which is necessary for browsers) and therefore I don’t think that it’s possible to get the URL without workarounds.
Note: The “Get URL” command doesn’t get the URL of Firefox windows - it opens specified URLs in new tabs/windows.
I have no idea of what i do but i copied&pasted this together, and it works 95% of the time
tell application "Firefox"
set theURL to «class curl» of front window
set theTitle to «class pTit» of front window
end tell
tell application "DEVONthink Pro"
set theArchive to create record with {name:theTitle, type:html, URL:theURL}
set data of theArchive to download web archive from theURL
end tell
You can place it in Library/Scripts/Applications/Firefox/ of your Homedirectory.
If someone would add this “try” and “on error” stuff… Or explain the above script…
Greetings, Louise.
P.S. Perhaps you should know that for 5% DEVONthink will crash - so you wont use this script on MyWorkOfLastFiveYears.dtBase before someone added error-handling
Hi, louise:
I’ve been running DT Pro and DA on my MacBook Pro for five weeks now, and still don’t have any crash logs. I want it to stay that way.
So thanks for the caveat/warning. Sorry, I’m not the guy to ask about figuring out the error handling. (And it might be a bug in WebKit, also. Looks like you just got the URL from Firefox and passed it to DT Pro, which is doing the downloading work.)
I think this bit of applescript works. I’ve added a check to make sure Firefox is running. Hopefully this will avoid any crashes. Let me know if it works for anyone else. Thanks.
tell application "System Events"
if ((application processes whose (name is equal to "firefox-bin")) count) is greater than 0 then
if (count of windows of application "Firefox") is greater than 0 then
tell application "Firefox"
try
set theURL to «class curl» of window 1
set theTitle to «class pTit» of window 1
end try
tell application "DEVONthink Pro"
activate
with timeout of 120 seconds
try
set theDestination to display group selector "Destination" buttons {"Cancel", "OK"}
set theArchive to create record with {name:theTitle, type:html, URL:theURL} in theDestination
set data of theArchive to download web archive from theURL
end try
end timeout
activate
end tell
end tell
else
return "Firefox is not running"
end if
else
return "Firefox is not running"
end if
end tell
Note: The “download web archive” command of v1.1.1 might sometimes crash, v1.1.2 will fix this.
Here is the same Applescript that now uses Growl notification. I realize that it doesn’t make much since to display the location in Growl after you just selected the location in DTP. This was just my first attempt to incorporate Growl notification with my applescripts.
--Define the Growl parameters
set growlMessage to " was saved to group--> "
set myNotice to "Simple notice"
set myGrowlApp to "Growl Applescripts"
set myTitle to "Save to Devonthink"
--Register this script with Growl using the DTP icon
tell application "GrowlHelperApp"
register as application myGrowlApp all notifications {myNotice} default notifications {myNotice} icon of application "DEVONthink Pro"
end tell
tell application "System Events"
if ((application processes whose (name is equal to "firefox-bin")) count) is greater than 0 then
if (count of windows of application "Firefox") is greater than 0 then
tell application "Firefox"
try
set theURL to «class curl» of window 1
set theTitle to «class pTit» of window 1
end try
tell application "DEVONthink Pro"
activate
with timeout of 120 seconds
try
set theDestination to display group selector "Destination" buttons {"Cancel", "OK"}
set theArchive to create record with {name:theTitle, type:html, URL:theURL} in theDestination
set data of theArchive to download web archive from theURL
end try
end timeout
end tell
activate
end tell
--Growl Notification of success
tell application "GrowlHelperApp"
set theGroup to (name of theDestination as string)
notify with name myNotice title myTitle description theTitle & growlMessage & theGroup application name myGrowlApp
end tell
else
tell application "GrowlHelperApp"
notify with name myNotice title myTitle description "Clipping failed. Firefox is not running!" application name myGrowlApp
end tell
end if
else
tell application "GrowlHelperApp"
notify with name myNotice title myTitle description "Clipping failed. Firefox is not running!" application name myGrowlApp
end tell
end if
end tell
So the crashs that occur from time to time are not due to the Firefox-part of the script? Thats good news! So with 1.1.2 it will be safe to take webarchives directly from Firefox - thats indeed great news!