DekGenius.com
Team LiB   Previous Section   Next Section
Desktop Print Manager

Syntax

tell app "Desktop Printer Manager"
   (* Find out which installed drivers can work with desktop printers; a 
   list of these drivers is stored in the drivers variable, if your 
   computer has any supported drivers *)
   set drivers to supported drivers
end tell

The following dictionary commands and classes are based on the Desktop Printer Manager Version 1.0. The DPM has been scriptable since Mac OS 8.5 (in fact, it was introduced with that OS version).

Dictionary commands

run

This command sends DPM a run Apple event to open it (this is not usually necessary since a tell statement targeting DPM will implicitly launch the application if it's not already open).

quit

This quits the DPM app. The DPM quits automatically after it is finished processing your script, unless its quit delay property is set to never. See the quit delay section elsewhere in this chapter.

make

You can make a new desktop printer with this command and give it some properties:

new desktop printer object

A required labeled parameter that always takes the form of:

make new desktop printer ...

not:

make new file

or some other object. See the desktop printer class description for a review of this object's properties.

at alias

This is a labeled parameter that lets you decide where to create the desktop printer icon. If you do not include this optional parameter then the desktop printer (DTP) is created on the desktop. An example is:

make new desktop printer at (alias "macintosh hd:desktop folder:printers:") 
with properties {name: "Laser",is default: true, driver name: "LaserWriter 8", 
address: addSpec } (* addSpec is a variable holding an address specification 
object *)

See the address specification class description elsewhere in this chapter.

with properties record

This is a record type that holds the properties of the new desktop printer. with properties is a required labeled parameter with the make command; the address and driver name properties have to be identified in this record. See the at parameter description preceding this segment for an example of the with properties parameter. Chapter 3, describes what a record data type is.

count

This command returns an integer representing the number of desktop printers:

count desktop printers or count each desktop printer.

each desktop printer

The each labeled parameter is optional. You do not have to use each if your code has the syntax:

count desktop printers

Otherwise use:

count each desktop printer

delete reference to desktop printer

You can delete a desktop printer with code such as:

tell app "Desktop Printer Manager" to delete desktop printer "Laser"

You can also identify the desktop printer to delete by its index:

delete desktop printer 1

If there is only one DTP then:

desktop printer 1

refers to it. If there is more than one DTP, your script has to be more specific in identifying them:

every desktop printer whose protocol is "AppleTalk"

Dictionary classes

application

The application class represents the Desktop Printer Manager program itself. This class has one or more desktop printer elements and four properties. The following is an application element:

desktop printer

This element represents one or more desktop printers. You can find out how many desktop printers there are with code such as:

tell app "Desktop Printer Manager" to count desktop printers

Or you can get a handle on a desktop-printer object by storing it in a variable:

tell app "Desktop Printer Manager" to set dtp to¬
                   desktop  printer 1

The following are application properties:

default printer (desktop printer object)

This is a settable property that allows a script to decide which desktop printer the computer sends its jobs to. If you are connected to more than one PostScript printer, then DPM scripting lets you dynamically choose which printer will do your printing at the moment.

supported drivers (list of strings; read-only)

This property returns a value like

{"LaserWriter 8"}

which is a list of drivers installed on the computer that support desktop printers.

quit delay (default/never or integer)

This property can be set to a constant, such as never or default, or to a certain number of seconds (e.g., 15). DPM will then quit after the last script command is processed and the specified number of quit-delay seconds has passed (or it will not quit automatically if you set this property to never). You could set this property to never if you expect to run DPM scripts several times during a computing session.

credits (string; read-only)

This is a self-congratulatory list of the Desktop Printer Manager programmers.

desktop printer

This class represents a desktop printer object. These objects are returned by the application's default printer property, as well as by the command desktop printers or every desktop printer, which will return a list of printers or an empty list if you do not have or cannot support desktop printers.

properties (record)

This desktop printer property returns a record type containing name/value pairs for various desktop-printer properties. The return value looks something like this:

{name:"Graphics printer", container:alias "Macintosh HD:Desktop
Folder:", is default:true, PPD file:generic, queue size:0, queue status:idle,
queue stopped:false, shows manual feed alert:true, address:{class:address 
specification, AppleTalk machine:" LaserWriter 16/600 PS", AppleTalk
zone:"Graphics_1", theme 
desktop pattern:"LaserWriter", protocol:AppleTalk}, driver name:"LaserWriter 8"}

name (string)

This is the name of the desktop printer as it appears on the desktop.

container (alias)

This property lets the script set the folder that contains the desktop printer:

set container of desktop printer 1 to alias "macintosh hd:desktop folder:today"

is default (boolean)

You can use is default to find out if a desktop printer object is the default printer:

if desktop printer 2 is default then set default printer to desktop printer 1

PPD file (generic constant or alias file path)

The PostScript Printer Description file property can be either the constant generic or an alias file path such as:

"macintosh hd:System Folder:Extensions:Printer Descriptions: LaserWriter 8500 
PPD v1.2" as alias

queue size (integer; read-only)

The queue size is the number of print jobs that the desktop printer has at the moment.

queue stopped (boolean)

This is a true/false value reflecting whether the print queue is stopped or not starting any print jobs.

queue status (constants idle/stopped/printing/alert; read-only)

The queue status value is one of these four constants. For example, if

tell app "Desktop Printer Manager" to get queue status of default printer

returns printing, then the default printer is printing at the moment.

shows manual feed alert (boolean)

A true/false value that turns this printer property on or off with the desktop printer object:

set default printer's shows manual feed alert to false

address (address specification object; read-only)

This represents the address or protocol/port configuration that the desktop printer is using. See the address specification class.

driver name (string; read-only)

This is the driver name as a string for this printer, as in "LaserWriter 8."

protocol (constants serial/AppleTalk/IP/SCSI/USB/custom/spool file/translator/unknown; read-only)

This is a constant representing the protocol used by the printer's address property.

address specification

This class, an instance of which is returned by the desktop printer object's address property, represents a device specification such as a Universal Serial Bus (USB) printer. The conduit property involves how the printer is connected to the computer, and the protocol determines how the machine communicates with its printer, such as over a TCP/IP network (an IP protocol).

properties (record)

This is a settable record of the address spec's properties (see the Examples section at the end of this chapter).

conduit (constants printer port, modem port, SCSI, USB, infrared)

This property is set to one of five constants. The conduit is the port by which printing data is sent.

protocol (constants serial, AppleTalk, IP, SCSI, USB, custom, spool file, translator unknown)

The protocol is the communication method between the desktop computer and the printing device or software. It can be set to one of nine constants, including custom.

AppleTalk address

This class designates the connection properties of a device that uses the AppleTalk networking protocol. See the Examples section at the end of this chapter. It inherits some properties from the address specification class, such as protocol.

AppleTalk machine (string)

This is the printer's name on the AppleTalk network.

AppleTalk zone (string)

This is the AppleTalk zone returned as a string, such as "Graphics_1."

AppleTalk type (string)

This is an AppleTalk type, such as "LaserWriter."

IP address

This class designates the connection properties of a device that uses the TCP/IP networking protocol.

This class inherits some properties from the address specification class, such as protocol.

ID (string)

This property is the IP address of the device as a string, such as "209.172.15.5."

queue name (string)

This is the queue name for this address as a string. It is not a required property if you are making a new desktop printer with the make command.

SCSI address

SCSI address designates the connection properties of a SCSI device.

This class inherits some properties from the address specification class, such as protocol.

ID (integer)

This is a SCSI ID number such as 5 (SCSI devices have unique ID numbers).

USB address

This class designates the connection properties of a USB device such as a USB printer.

USB address inherits some properties from the address specification class, such as protocol.

name (string)

This is the USB device's name as a string.

translator address

Your desktop printer might actually be software that translates PostScript code (a PostScript file is usually identified with a .ps suffix). The desktop printer object's protocol would be translator. This class represents a PostScript translator output folder.

translator address inherits some properties from the address specification class, such as protocol.

destination folder (alias)

This is the alias file path for the folder that will contain the translated output.

custom Printer address

This class represents the configuration of a custom printer, which is not described by the other address specification types.

custom Printer addressinherits some properties from the address specification class, such as protocol.

target application (alias)

This is the alias file path for an application that will process the printer data.

Examples

set err to "" --this will hold any error messages
tell app "Desktop Printer Manager"
   set addSpec to {class: address specification, AppleTalk machine:¬
   "LaserWriter 16/600 PS", AppleTalk zone: "Graphics_1",¬
   AppleTalk type: "LaserWriter", protocol: AppleTalk }
   try -- check for errors in making a new desktop printer
      make new desktop printer with properties { name: "Graphics¬ printer",
driver name: "LaserWriter 8", address:  addSpec, is default:
      true }
      on error errMesg
      set err to errMesg
   end try
end tell
if length of err > 0 then display dialog "An error occurred when making¬
the desktop printer; it was:" & err

    Team LiB   Previous Section   Next Section