|
|
#1 |
|
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 |
|
|
|
|
|
#2 |
|
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. |
|
|
|
|
|
#3 |
|
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 |
|
|
|
|
|
#4 |
|
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. |
|
|
|
|
|
#5 |
|
Prospect
Join Date: Aug 2005
Posts: 43
|
Thanks. It all works great now. I really appreciate it.
- D |
|
|
|
|
|
#6 |
|
Registered User
Join Date: Dec 2005
Posts: 1
|
Is it not possible instead of printing that the saveas PDF can be selected by applescript ?
|
|
|
|
|
|
#7 | |||||||||||||||||||||||
|
Prospect
Join Date: Feb 2005
Posts: 10
|
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. |
|||||||||||||||||||||||
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|