Apple Events

The Mac OS version of PageMaker supports Apple Events. Other applications may send commands and queries to PageMaker via Apple Events, using the PageMaker scripting language.

A major advantage of interapplication communication (IAC) is that it lets you integrate the functionality of multiple applications. For example, you could write an application that automates the production of a catalog. It could open a database application, extract any new product descriptions from the catalog database, and then open PageMaker, locate the previous descriptions in the catalog, and replace both the descriptions and the images.

About IAC with Apple Events

Note: We assume you're familiar with the way Apple Events and the Apple Event manager work. If you're not, you may want to refer to Inside Macintosh, Interapplication Communication by Apple Computer, Inc. before reading this information.

The Macintosh protocol using Apple Events is very similar to the protocol used on the PC. Rather than use a separate Apple Event ID for each command and query, a plug-in uses one of two Apple Event IDs to deliver commands or queries to PageMaker: DOSC and EVAL. DOSC can deliver multiple ASCII commands.

Unlike some applications, PageMaker does not distinguish between commands and queries at the Apple Event level. Therefore, you can use either of the two supported events-Do Script and Evaluate Expression-to send commands and queries to PageMaker. (PageMaker supports both events to provide compatibility with applications that cannot use these standard Apple Events interchangeably.)

In addition, PageMaker supports the four "required" Apple Events: Open Application, Open File, Print, and Quit.

Addressing events to PageMaker

In general, you can use several methods to address Apple Events to a specific application: the application signature, the session ID, the target ID, or the process serial number. The approach depends on the application you're using. To learn about each method and determine which best suits your needs, refer to Inside Macintosh, Interapplication Communication.

Note: PageMaker's application signature is "ALD6."

Required constants

To communicate with PageMaker using AESend, your plug-in must identify these constants:

Sample code

To see how Apple Events send commands or queries to PageMaker, review the sample code included in this SDK. The Do script and Evaluate Expression events send both commands and queries to PageMaker.

Note: PageMaker does not distinguish between the Do Script and Evaluate Expression events. PageMaker recognizes both events to accommodate applications that require both.

Sending commands and queries

When you send commands and queries to PageMaker via an Apple Event:

Note: It is possible to send events to PageMaker faster than PageMaker can process them. In that case, events may be ignored. To circumvent the problem, you should always specify a kAEWaitReply in the sendMode parameter of AESend, even if your plug-in is only sending commands.

PageMaker's reply to a query

PageMaker uses the reply Apple Event to provide query results or error information to the application sending the Apple Event. Replies may contain:

Note: If an error occurs, the reply may also contain invalid data in keyAEDirectParameter. To verify whether the data is valid, make sure the reply contains keyAEDirectParameter and does not contain the keyErrorNumber parameter.

A successful query reply in keyAEDirectParameter:

HyperCard or SuperCard example

The following HyperCard or SuperCard example creates a simple utility that threads (joins) the text of two independent text blocks into one story and then replaces the second text block in its original position. The utility consists of a button, which sends the commands and queries to select, join, and replace the text, and a simple text field, where user instructions are displayed.

To use this threading utility, you should have a publication open in PageMaker with at least two stories on the page.

Note: You must use HyperCard version 2.1 or later. Also, program linking must be active in the Sharing Setup control panel for this example to work.

Stack or project script

The following function is the stack or project script for the utility:

--Threading utility courtesy David Butler

function sendQueryToPM pmscript

global PMAPP

-- put PageMaker name into variable PMAPP

if PMAPP is empty then

answer program "Select PageMaker from list on right:"

if it is empty then exit sendQueryToPM

put it into PMAPP

end if

request pmscript from program PMAPP

return it

end sendQueryToPM

Button

The utility has one button named Thread. The script for the button is:

on mouseUp

-- Get coordinates of selected text block

-- Use coordinates later to place text back on page

put sendQueryToPM("getobjectloc topleft") into TLCoords

put sendQueryToPM("getobjectloc bottomright") into BRCoords

 

-- Highlight and cut text from second text block

-- Select first text block

put sendQueryToPM("textedit;selectall;cut;select 1;") into reply

 

-- Get bottom corner of first text block

put sendQueryToPM("getobjectloc bottomright") into BCd

 

-- Get last character of first text block

put sendQueryToPM("textedit;textcursor +textblock;textselect -char") into reply

put sendQueryToPM("getstorytext 0 0") into reply

 

-- If last character is not a return, add one

If character 2 of reply is return then

put "textcursor +textblock;" into TxtSend

else

put "textcursor +textblock;textenter " & quote & return & quote & ";" into TxtSend

end if

 

-- Paste text and reposition text blocks

put "paste;select 1;resize bottomright" && BCd & ";" after TxtSend

put "placenext;place" && TLCoords & ";" after TxtSend

put "resize topleft" && TLCoords & ";" after TxtSend

put "resize bottomright" && BRCoords & ";" after TxtSend

put sendQueryToPM(TxtSend) into reply

end mouseUp

Text field

The utility has one text field that contains the following instructions for the user:

To thread two text blocks, select the first text block and send it to the back. Then, select the second block and click Thread.


Comments or suggestions? Contact Adobe Developer Support
Copyright © 1997 - 2001 Adobe Systems Incorporated. All rights reserved.
Legal notices and trademark attributions