Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

An AppleScript to print a 'daily' URL via Firefox Web Browsers
After looking around for a simple script to print web pages (the daily Dilbert cartoon, in this case) using AppleScript and not finding one, I decided to write one of my own.

The script I wrote does the following:
  1. Generates a URL based on today's date and a base URL.
  2. Opens the URL in Firefox (Could easly use Safari).
  3. Opens the print dialog.
  4. Chooses a desired print preset (modify this to match your setup).
  5. Prints the URL.
To use, run the text through Script Editor and save as an AppleScript -- preferably to your ~/Library/Scripts folder, where it'll be easily accessible from anywhere.

[robg adds: This worked as described for me...]
    •    
  • Currently 2.67 / 5
  You rated: 2 / 5 (6 votes cast)
 
[20,535 views]  

An AppleScript to print a 'daily' URL via Firefox | 3 comments | Create New Account
Click here to return to the 'An AppleScript to print a 'daily' URL via Firefox' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
An AppleScript to print a 'daily' URL via Firefox
Authored by: yanokwa on Jan 26, '06 02:36:12PM
Pseudo-related is a list of comic apps and some of them are even Dilbert specific.

[ Reply to This | # ]
An AppleScript to print a 'daily' URL via Firefox
Authored by: cfoster on Jan 30, '06 03:26:59AM

Here's another option that doesn't require any browser, or require that you allow access to the user interface via AppleScript (which can be a security concern). It uses the 'curl' and 'grep' commands to find just the cartoon in the web page. It then saves the image to a temp file, and uses Preview to print it.

-- URL is in the form of {URL_BASE, "yyyymmdd.html"
set UrlBase to "http://dilbert.com/comics/dilbert/archive/dilbert-"
set DayString to day of (current date)
set MonthString to month of (current date) as number
set YearString to year of (current date)

--Add zero padding for days/months less than 10 (required URL format)
if (DayString < 10) then set DayString to "0" & DayString
if (MonthString < 10) then set MonthString to "0" & MonthString

-- Set date portion of URL
set dateString to YearString & MonthString & DayString as string

-- Retrieve the HTML block that contains today's Dilbert
set img_html_block to do shell script "curl http://dilbert.com/comics/dilbert/archive/dilbert-" & 
	dateString & ".html | grep -e SRC=\\"/comics/dilbert/archive"

-- Find the specific location of the img src string and truncate to its start.
set img_path_start to offset of "/comics/dilbert/archive" in img_html_block
set img_html_block to text img_path_start through (length of img_html_block) of img_html_block

-- Find where the path ends and build the absolute path of the comic. Determine gif or jpg file type.
set img_ext to ".gif"
set img_path_end to offset of img_ext in img_html_block
if (img_path_end is equal to 0) then
	set img_ext to ".jpg"
	set img_path_end to offset of img_ext in img_html_block
end if
set comic_path to "http://dilbert.com" & (text 1 through (img_path_end + 3) of img_html_block)

-- Grab just today's comic and save it to a temp file.
set temp_file to "/private/tmp/dilbert" & dateString & img_ext
do shell script "curl " & comic_path & " >" & temp_file

-- Check if Preview is already running.
tell application "Finder"
	try -- If this fails, preview wasn't running.
		set preview_was_running to ((name of process "Preview") is equal to "Preview")
	on error
		set preview_was_running to false
	end try
end tell

-- Launch Preview (if necessary) and have it print the image.
tell application "Preview" to print ((POSIX file temp_file) as text)

-- We should quit preview if it wasn't running before this script ran.
if (preview_was_running is equal to false) then
	delay 1 -- give it a second to fire off the image to the print queue.
	tell application "Preview" to quit
end if

-- Clean up our temp file.
do shell script "rm " & temp_file



[ Reply to This | # ]
Safari
Authored by: 5chm31din6 on Jul 07, '06 06:59:52PM

How 'bout showing us how to do this with Safari as well? Saying it can be easily done doesn't mean we all know how to do it. I tried to convert this to a Safari version and am stumped.

---
Power corrupts. PowerPoint corrupts absolutely.



[ Reply to This | # ]