|AppleScript support in PDF 2 PSP||Back|
AppleScript is a very easy-to-use language for automating and extending Macintosh OS X. The purpose of this document is not to teach you Applescript, however, but to show how Applescript can be used to control PDF 2 PSP. For example, here is a simple Applescript that displays the current settings of PDF 2 PSP:
tell application "PDF2PSP" display dialog "Current output directory = " & ¬ (output directory as string) & ", resolution = " & ¬ resolution & ", orientation = " & ¬ orientation & " and quality = " & quality end tell
For more information about AppleScript in general, and for many sample scripts and tutorials, see Apple's own web site: AppleScript.
PDF 2 PSP has only one Applescript class, the application itself. Within that class, it supports all the standard Applescript application properties and three custom properties. These properties correspond to four of the settings on the PDF 2 PSP window:
- How large you want the converted images to be. The
possible values are:
0 - Fit to Screen
1 - Fit to Width
2 - Original Size
3 - 2x Screen Width, and
4 - High Resolution.
- Whether or not the images will be rotated. Values are:
0 - Portrait (upright) and
2 - Landscape (sideways).
- A decimal number between 0 and 1. Values closer to zero will produce smaller images but may be blurry or have strange "artifacts" in them. Values closer to one will produce much larger images, but they will be as sharp as possible.
- output directory
- The place where PDF 2 PSP will write the images to. Note that this is an Applescript "alias", which is different from a URL or Unix path.
Each of these properties can be read or written to. For instance, the sample script at the top of this document reads all four and displays the results in a dialog box. You set them in a similar manner:
tell application "PDF2PSP" to set resolution to 3 tell application "PDF2PSP" to set output directory to "::tmp"
A final note about these properties. PDF 2 PSP remembers its settings from one run to the next - even settings that come from an Applescript. If this is not what you want, you have to save the old settings and then restore them when the script is done:
tell application "PDF2PSP" set oldDirectory to output directory set oldQuality to quality (do some stuff here) set output directory to oldDirectory set quality to oldQuality end tell
Currently, PDF 2 PSP has only one command: convert. Convert takes one or two arguments. The first is the name of the file to convert. The second is whether to overwrite or not:
convert pdffile myfile
convert pdffile myfile with overwrite
The overwrite option tells PDF 2 PSP that, if you have already run it before on the same PDF file, go ahead and replace those old images with new ones. Otherwise, PDF 2 PSP will ask you if you really want to erase the old images. Here's another sample script:
tell application "PDF2PSP" set resolution to 3 set quality to 0.80 convert pdffile ("/tmp/myfile.pdf" as POSIX file) end tell
The second time you run that script, PDF 2 PSP will complain: "Output directory "myfile" already exists. Do you want to continue?" You can click on "OK" if you want, or "Cancel". But if you don't want to see the warning at all, you can change your script:
tell application "PDF2PSP" set resolution to 3 set quality to 0.80 convert pdffile ("/tmp/myfile.pdf" as POSIX file) with overwrite end tell
You can find one really cool sample script called " in the Tips section. This script works with the "PDF workflow automation" that's built into OS X. By installing it in your "Library/PDF Services" directory, you change the standard print dialog box. At the bottom you will now have a button with a picture of a PDF file. If you click that button, you can choose the script from a pop-up menu. If you do that, the Mac will send your print out to the script instead of to your printer.
Other scripts will be made available on the Sourceforge website as I think of them or people send them to me!
© 2005, Michael W. Heinz, Sr - aka "Porkchop D. Clown". All rights reserved.
|Back to PDF 2 PSP Help|