Go Back   The macosxhints Forums > OS X Help Requests > System



Reply
 
Thread Tools Rate Thread Display Modes
Old 11-21-2005, 01:00 PM   #1
duklaa
Prospect
 
Join Date: Aug 2005
Posts: 43
Applescript for saving as PDF

Are there any Applescripts that allow me to automate saving to PDF? (In particular saving all open tabs in the browswer as PDF files).

Thanks.

- D
duklaa is offline   Reply With Quote
Old 11-21-2005, 04:01 PM   #2
ever
Prospect
 
Join Date: Feb 2005
Posts: 10
Not that I'm aware of, but I wrote one for you. This requires that you set up a virtual PDF printer. A PDF printer is a great thing to have, and can help with automating PDF conversion in just about any app, including ms word. It's free, but the setup process is somewhat involved. Go here for the how-to:
http://www.macosxhints.com/article.p...31116190809396

Here's the script:
Code:
(*
This script cycles through Safari tabs, and
prints each page to a virtual PDF printer.

To set up a PDF printer in OS X, follow
the instructions on this page:

http://www.macosxhints.com/article.php?story=20031116190809396
*)

set printer_name to "PDFWriter"
set print_history to {}

if check_gui() is true then
	activate application "Safari"
	repeat
		tell application "Safari"
			set this_page to URL of document 1
			if this_page is not in print_history then
				copy this_page to the end of print_history
				print the front document with properties {target printer:printer_name} without print dialog
				tell application "System Events" to tell front menu bar of application process "Safari"
					click menu item "Select Next Tab" of front menu of menu bar item "Window"
				end tell
			else
				exit repeat
			end if
		end tell
	end repeat
end if


on check_gui()
	tell application "System Events"
		get system attribute "sysv"
		if result is greater than or equal to 4144 then -- Mac OS X 10.3.0
			if UI elements enabled then
				return true
			else
				beep
				display dialog "GUI Scripting is not enabled" & return & return & "Open System Preferences and check Enable Access for Assistive Devices in the Universal Access preference pane, then run this script again." with icon stop
				if button returned of result is "OK" then
					tell application "System Preferences"
						activate
						set current pane to pane "com.apple.preference.universalaccess"
					end tell
				end if
			end if
		else
			beep
			display dialog "This computer cannot run this script" & return & return & "The script uses GUI Scripting technology, which requires an upgrade to Mac OS X 10.3 Panther or newer." with icon caution buttons {"Quit"} default button "Quit"
		end if
		return false
	end tell
end check_gui

Last edited by ever; 11-21-2005 at 05:05 PM.
ever is offline   Reply With Quote
Old 11-21-2005, 07:11 PM   #3
duklaa
Prospect
 
Join Date: Aug 2005
Posts: 43
Great! Thanks so much. I really appreciate it.

I tried to create a PDF Printer via the link you posted. Everything works fine about creating the script. However, I am unable to install the Printer properly using the Printer Setup Utility.

I don't see "Advanced" when I option-click the Add button (in fact, the "Add" dialog is the same with or without option button). I see the following options in the Add dialog box:
Protocol: (I selected Line Printer Daemon),
Address: (I tried /usr/libexec/cups/backend/pdf and pdf://tmp)
Queue: (I left blank)
Name: (PDFWriter)
Location: (I tried /usr/libexec/cups/backend/pdf)
Print Using: (Generic PostScript Printer).

Whenver I print to this printer, a dock icon named with the printer name show up. And it says that the job was stopped. No pdf (or log) file is generated.

Any clues what I am doing wrong?

Thanks again for the help.

- D
duklaa is offline   Reply With Quote
Old 11-21-2005, 07:48 PM   #4
ever
Prospect
 
Join Date: Feb 2005
Posts: 10
Ah-ha! I thought that hint was old. I actually followed the instructions left in the comments at the end of that page, but on looking at it today I didn't think there was any real difference between the two other than that the second version had a lot of typos and missing words. The difference is that you hold down option not while clicking add, but while clicking More Printers...



Sorry about the mixup. I'm tempted to write my own version of that procedure because I see this question pop up on message boards a lot.
ever is offline   Reply With Quote
Old 11-22-2005, 03:13 AM   #5
duklaa
Prospect
 
Join Date: Aug 2005
Posts: 43
Thanks. It all works great now. I really appreciate it.

- D
duklaa is offline   Reply With Quote
Old 12-14-2005, 05:15 AM   #6
jphermans
Registered User
 
Join Date: Dec 2005
Posts: 1
Is it not possible instead of printing that the saveas PDF can be selected by applescript ?
jphermans is offline   Reply With Quote
Old 12-14-2005, 10:47 AM   #7
ever
Prospect
 
Join Date: Feb 2005
Posts: 10
Quote:
Originally Posted by jphermans
Is it not possible instead of printing that the saveas PDF can be selected by applescript ?

You can do that on most pre-Tiger versions of Mac OS X. In Tiger, however, the PDF print button has been changed such that it can't be manipulated by AppleScript the way it was before.
ever is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 10:27 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Site design © Mac Publishing LLC; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of Mac Publishing LLC.