TweetFollow Us on Twitter

Introduction to Scripting QuarkXPress

Volume Number: 22 (2006)
Issue Number: 10
Column Tag: AppleScript Essentials

Introduction to Scripting QuarkXPress

by Benjamin S. Waldie

My last two columns have focused on using AppleScript to automate graphic processing with Photoshop and GraphicConverter. This month, we are going to switch gears from graphic processing to discuss another commonly automated creative process - desktop publishing. Specifically, we will explore some initial steps necessary for automating a desktop publishing workflow using QuarkXPress, a popular page layout application.

History

QuarkXPress was one of the first applications to support AppleScript, with version 3.2. In fact, it is believed by some that QuarkXPress is actually partially responsible for AppleScript being around today. Rumor has it that, at one time, Apple had planned to do away with AppleScript, but received such a backlash from the publishing community, who threatened to move to PCs if their scripted workflows were taken away, that it was decided to keep AppleScript around.



Figure 1. QuarkXPress 7's New Icon

One great aspect of Quark's AppleScript support is its commitment to backward-compatibility. From the early days to today with version 7, see figure 1, Quark's AppleScript support has not changed all that much. New terminology has been added for new application features. However, existing terminology has stayed relatively the same, with only minor modifications along the way. This has allowed many users to upgrade their scripts for new versions of Quark without the hassle of making a large number of adjustments. In fact, the recent jump from Quark 6 - 7 introduced only a handful of changes to existing AppleScript terminology, allowing many Quark 6 scripts to function in Quark 7 without any changes whatsoever.

Getting Started

As you begin scripting Quark, be sure to refer to Quark's AppleScript dictionary regularly to determine the proper terminology to use. (See figure 2.) You will find that Quark's dictionary is broken into a number of logical suites of classes and commands, and that Quark's containment hierarchy is fairly straightforward.



Figure 2. QuarkXPress' AppleScript Dictionary

For Quark 6.x users, I highly recommend downloading and installing an updated copy of the Script.xnt XTension. This updated XTension will fix problems that may occur when printing Quark documents to PostScript format in Mac OS X 10.4 and higher. This XTension is part of a package named Output Enhancements XTensions software (user mode) for QuarkXPress and QuarkXPress Passport 6.5. This package is available for download from the Support > Desktop Downloads section of Quark's website at <http://www.quark.com/service/desktop/downloads/details.jsp?idx=601>.

Getting to Know Quark Projects

In QuarkXPress, the document in which you will work is known as a project, and a project contains one or more layout spaces. For example, a project could contain a print layout, a web layout, and more. Prior to Quark 6, layout spaces did not exist, nor did projects. At that time, a document was simply called a document.

As far as AppleScript is concerned, Quark's AppleScript terminology contains project, layout space, and document classes. The document class exists to allow for compatibility with scripts written for older versions of Quark.

When referring to a project in Quark, you do so as follows:

tell application "QuarkXPress"
   tell project 1
      -- Do something
   end tell
end tell

The code above would refer to the frontmost project. The following code demonstrates how you would address a layout space within that project. In this case, the first layout space is being addressed. Even if the project only has one layout space, you must still address the layout.

tell application "QuarkXPress"
   tell layout space 1 of project 1
      -- Do something
   end tell
end tell

As mentioned before, Quark also supports a class of document, which you may use if you choose to. For example:

tell application "QuarkXPress"
   tell document 1
      -- Do something
   end tell
end tell

Referring to a document in this manner is essentially the same as referring to the current layout space of a project. In this example, document 1 refers to the frontmost project document.

In the examples above, I referred to projects, layout spaces, and documents by their index, or front to back ordering. Of course, you may also refer to projects, layout spaces, and documents by their names, if desired. For example:

tell application "QuarkXPress"
   tell layout space "Layout 1" of project "Project1"
      -- Do something
   end tell
end tell

Creating a Project

To create a new project with a single layout space in QuarkXPress, use the make command, the result of which will be a reference to the newly created project. For example:

tell application "QuarkXPress"
   make new project at beginning
end tell
--> project "Project1" of application "QuarkXPress"

In Quark, layout spaces within the same project can be different sizes. In the code above, we did not specify a height and width for the layout space in the newly created project. Because of this, Quark's current default size settings will be used to create the project. However, these can be adjusted by modifying the page height and page width properties of the default document class, prior to creating the project. For example, the following code would create a project containing a layout space that is 6 inches high and 8 inches wide.

tell application "QuarkXPress"
   tell default document 1
      set page height to "6 in"
      set page width to "8 in"
   end tell
   make new project at beginning
end tell
--> project "Project1" of application "QuarkXPress"

The layout space class itself also has page height and page width properties, which can be modified after the project is created, if desired. For example, the following code would create a new project with a single layout space that is 4 inches high by 4 inches wide.

tell application "QuarkXPress"
   set theProject to make new project at beginning
   tell layout space 1 of theProject
      set page height to "4 in"
      set page width to "4 in"
   end tell
end tell

Creating a New Layout Space

The make command may also be used to create a new layout space within an existing project. In doing so, you may choose to specify properties of the layout space, such as page height and page width. For example:

tell application "QuarkXPress"
   tell project 1
      make new layout space at end with properties {page height:"11 in", page width:"8.5 in"}
   end tell
end tell

Working with Text

Creating a Text Box

A key aspect of scripting Quark involves working with text. In Quark, text is placed into text boxes on pages within layout spaces. To create a text box via AppleScript, you will need to determine where you would like the text box to be created, and how large you would like it to be.

First, determine the page on which the text box should be created. Next, determine where you would like the box to be positioned on that page, and how large it should be. This information will be communicated to Quark using a list of bounds. This list will be formatted as follows:

   {top position, left position, bottom position, right position}

Now, to create the text box, use the make command, and specify the bounds for the box as follows:

tell application "QuarkXPress"
   tell page 1 of layout space 1 of project 1
      make new text box at beginning with properties {bounds:{"1 in", "1 in", "3 in", "6 in"}}
   end tell
end tell
--> text box 1 of page 1 of layout space "Layout 1" of project "Project1" of application 
   "QuarkXPress"

Using the code above, a text box would be created on page 1 of the layout space. The top left corner of the box would be one inch down, and one inch from the left side of the page. The bottom right corner of the box would be 3 inches down, and 6 inches from the left side of the page. Therefore, this text box would be 2 inches high and 5 inches across.

Placing Text

In Quark, a story represents all of the text within a text box. Once a text box exists, you may set its text to a specified string by setting the value of its story element. For example:

tell application "QuarkXPress"
   tell page 1 of layout space 1 of project 1
      set story 1 of text box 1 to "My Project Text"
   end tell
end tell

Please note that the code above would replace existing text in the box, if present.

Styling Text

Stories possess numerous text properties, which are modifiable via AppleScript. I will cover only a few of these in this column. I encourage you to explore Quark's AppleScript dictionary for a complete list of these properties. Please note that many of these are found under the text properties and character properties classes, which are inherited by the story class.

The following example code demonstrates the modification of a number of different character properties within a story, including font, size, and color. As you can see, values for these properties may be applied to the story itself, such as in the case of the font property below. Or, values may be applied to elements of the story, such as specific paragraphs, words, or characters.

tell application "QuarkXPress"
   tell page 1 of layout space 1 of project 1
      tell story 1 of text box 1
         set font to "Arial"
         set size of word 2 to 24
         set color of word 1 to "Yellow"
         set color of word 2 to "Cyan"
         set color of word 3 to "Magenta"
      end tell
   end tell
end tell

Figure 3 shows an example of a text box containing text that was styled using the example code above.



Figure 3. Styled Text in QuarkXPress

Working with Pictures

Creating a Picture Box

As you will find, working with picture boxes in Quark is very similar to working with text boxes. To create a picture box, use the make command, and specify a value for the box's bounds property. Again, the bounds of the box will indicate its size and positioning on the specified page. The following example code will create a 3 inch high by 5 inch wide picture box.

tell application "QuarkXPress"
   tell page 1 of layout space 1 of project 1
      make new picture box at beginning with properties {bounds:{"3 in", "1 in", "6 in", "6 in"}}
   end tell
end tell
--> picture box 1 of page 1 of layout space "Layout 1" of project "Project1" of application 
   "QuarkXPress"

Placing a Picture

Once you have created a picture box, you will probably want to place a picture within it. To do this, set its image to a specified file path. For example:

set theImage to choose file with prompt "Please select an image to place:" without 
   invisibles
tell application "QuarkXPress"
   tell page 1 of layout space 1 of project 1
      tell picture box 1
         set image 1 to theImage
      end tell
   end tell
end tell

Figure 4 demonstrates a picture box in Quark that has been populated with an image file using the example code above.



Figure 4. A Placed Picture

Naming Boxes

In most of the examples so far, we have referred to text and picture boxes by their index, i.e. front to back ordering on the page. The problem with writing a script in this manner is that the ordering of the boxes on a page may change if boxes are added, grouped, or deleted.

To get around this limitation, and ensure that your script is always interacting with the correct boxes, it is good practice to assign names to boxes in your Quark documents. Just as projects, layout spaces, and documents can be referred to by name, text and picture boxes can also be referred to by name. The problem, however, is that Quark does not provide an interface for naming text and picture boxes. Therefore, this must by done using AppleScript, by modifying the name property of the desired box. For example:

tell application "QuarkXPress"
   tell page 1 of layout space 1 of project 1
      tell text box 1
         set name to "Photo Description"
      end tell
   end tell
end tell

Once a name has been assigned to a box, you can use its name, rather than its index, to refer to the box. For example:

tell application "QuarkXPress"
   tell page 1 of layout space 1 of project 1
      set text of text box "Photo Description" to "Photo Description"
   end tell
end tell

Next Steps and Resources

Documentation and Examples

If you are a serious QuarkXPress user, and you are planning to make yourself more efficient by introducing AppleScript automation into your workflow, there are several ways to get started. First, be sure to view Quark's Guide to Apple Events Scripting documentation. This is installed along with QuarkXPress, and can be found in the Documents > Apple Events Scripting folder in the main QuarkXPress folder.

Also, in the Apple Events Scripting folder, you will find a sample Layout Construction AppleScript file, which contains some example code to get you started. This script is unlocked and editable for you to modify, or to borrow code for insertion into your own scripts.

If you're interested in finding even more documentation on scripting QuarkXPress, you may want to check out X-Ray Magazine at <http://www.xraymag.com/>. X-Ray is geared entirely for Quark users, and (excuse the shameless plug), in addition to writing for MacTech, I also write a regular AppleScript column for X-Ray on... you guessed it, AppleScripting QuarkXPress.

If the above resources still can't contain your quest for more QuarkXPress AppleScript knowledge, then you should check out AppleScripting QuarkXPress, by Shirley Hopkins, which is available (although in short supply) from Amazon.com at <http://www.amazon.com/gp/product/0970726503/>.

Expanding QuarkXPress' AppleScript Support

Inevitably, you may encounter things that you wish were scriptable in Quark, but unfortunately, simply are not. Well, before you get too upset, you may want to check around to see if there is a third-party XTension that will add the functionality that you need. Quark's XTension architecture allows developers to create their XTensions that actually add new AppleScript terminology to Quark's dictionary. One such developer is Em Software (http://www.emsoftware.com), whose Xcatalog and Xdata XTensions are scriptable, and can allow users to automate quite complex document construction workflows. Gluon (http://www.gluon.com) is another developer that offers a number of scriptable XTensions for QuarkXPress.

Recording AppleScript Code in QuarkXPress

The dream of anyone getting started on scripting QuarkXPress, is to be able to record tasks they perform manually using the Script Editor's record functionality. Unfortunately, QuarkXPress (like most applications) does not support AppleScript recordability. To get around this limitation, however, be sure to check out ScriptMasterXT, a commercial XTension for QuarkXPress, available from Jintek, LLC (http://www.jintek.com/). ScriptMasterXT adds AppleScript recordability, as well as numerous useful AppleScript commands, to QuarkXPress. A limited demonstration version of ScriptMasterXT is available for download from the Jintek website.

In Closing

We have really only scratched the surface of scripting QuarkXPress. There are many, many more tasks that can be automated in Quark using AppleScript, and I would encourage you to continue exploring them on your own. With a little work, it's easily possible to automate even the most complex Quark-based workflows using AppleScript.

Until next time, keep scripting!


Ben Waldie is the author of the best selling books "AppleScripting the Finder" and the "Mac OS X Technology Guide to Automator", available from <http://www.spiderworks.com>, as well as an AppleScript Training CD, available from <http://www.vtc.com>. Ben is also president of Automated Workflows, LLC, a company specializing in AppleScript and workflow automation consulting. For years, Ben has developed professional AppleScript-based solutions for businesses including Adobe, Apple, NASA, PC World, and TV Guide. For more information about Ben, please visit <http://www.automatedworkflows.com>, or email Ben at <ben@automatedworkflows.com>.

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Pro Tools 2022.5 - Professional audio ed...
Pro Tools offers audio professionals superb quality and efficiency through one intuitive, integrated production environment. This high-definition system embodies the latest Digidesign innovations,... Read more
Evernote 10.38.1 - Create searchable not...
Evernote allows you to easily capture information in any environment using whatever device or platform you find most convenient, and makes this information accessible and searchable at anytime, from... Read more
calibre 5.43.0 - Complete e-book library...
Calibre is a complete e-book library manager. Organize your collection, convert your books to multiple formats, and sync with all of your devices. Let Calibre be your multi-tasking digital librarian... Read more
Mellel 5.1.2 - The word processor for sc...
Mellel is the leading word processor for OS X and has been widely considered the industry standard for long form documents since its inception. Mellel focuses on writers and scholars for technical... Read more
FileZilla 3.60.0 - Fast and reliable FTP...
FileZilla (ported from Windows) is a fast and reliable FTP client and server with lots of useful features and an intuitive interface. The FileZilla Client not only supports FTP, but also FTP over TLS... Read more
Parallels Desktop 17.1.3 - Run Windows a...
Parallels allows you to run Windows and Mac applications side by side. Choose your view to make Windows invisible while still using its applications, or keep the familiar Windows background and... Read more
iMazing 2.15.0 - Complete iOS device man...
iMazing is the world’s favourite iOS device manager for Mac and PC. Millions of users every year leverage its powerful capabilities to make the most of their personal or business iPhone and iPad.... Read more
Nitro PDF Pro 13.2.1 - Advanced PDF tool...
Nitro PDF Pro allows users to edit PDF's easily. Add text, images and signatures. Fill out PDF forms. Merge or split PDF documents. Reorder and delete pages. Create fillable forms and tables of... Read more
Nitro PDF Pro Essentials 13.2.1 - Edit a...
Nitro PDF Pro Essentials allows users to easily edit PDF's. Add text, images and signatures. Fill out PDF forms. Merge or split PDF documents. Reorder and delete pages. Even correct text and edit... Read more
Adobe InDesign 17.3 - Professional print...
InDesign is available as part of Adobe Creative Cloud for as little as $20.99/month (or $9.99/month if you're a previous InDesign customer). Adobe InDesign is part of Creative Cloud. That means you... Read more

Latest Forum Discussions

See All

Help TikTok Pool Guy, I Need You – The T...
It’s official! The video podcast is back for all you Patreon supporters. Turns out the answer was right in front of us all along: Zoom. Yes, Zoom! Duh! I don’t know why we didn’t think to try that before. Anyhoo, this week’s show is stuffed to the... | Read more »
TouchArcade Game of the Week: ‘Streets o...
It was a stacked week of great new mobile game releases, and it was a really hard week to pick just one for the Game of the Week. It seems like that’s been the case a lot lately, which just means that us mobile gamers are eating quite well as of... | Read more »
SwitchArcade Round-Up: ‘Pac-Man Museum+’...
Hello gentle readers, and welcome to the SwitchArcade Round-Up for May 27th, 2022. In today’s article, we’ve got even more new releases than yesterday to look at. Pac-Man Museum+, Kao the Kangaroo, Remote Life, and Arcade Spirits: The New... | Read more »
Steam Deck Update Reduces Fan Noise, Add...
Today, Valve pushed out another major update for SteamOS on Steam Deck. This update focuses on reducing fan noise with some useful features finally implemented. If you missed our review, see what Jared thought of it at launch here. | Read more »
Pro Darts 2022+ Is Out Now on Apple Arca...
As revealed before, Pro Darts 2022+ () from iWare Designs has gone live on Apple Arcade today as the final May 2022 addition on the service. Pro Darts 2022+ is from the developers who brought us Pro Snooker & Pool 2022+. The App Store version... | Read more »
Strategy Game ‘SD Gundam G Generation Et...
Bandai Namco Entertainment just announced a brand new Gundam strategy game titled SD Gundam G Generation Eternal. SD Gundam G Generation Eternal is a free to play game for iOS and Android that lets you collect your favorite Mobile Suits from the... | Read more »
‘Genshin Impact’ Version 2.7 Pre-Install...
Genshin Impact (Free) version 2.7 update finally releases next week across all platforms following a bit of a delay. Developer HoYoverse previously showcased Yelan in a new character trailer with details for the update being revealed a little while... | Read more »
‘Delete After Reading’ is a New Genre-Mi...
Back in October of 2020, developer Patrones & Escondites released a very unique titled called Unmemory. It’s one part interactive fiction, one part puzzle game, and multiple parts escape room or alternate reality game. Its back-of-the-box pitch... | Read more »
‘Jurassic World Primal Ops’ is a Hero Co...
Did you know that there’s a new Jurassic World movie coming out in just a couple of weeks? Chances are that the movie’s marketing machine has beaten you over the head with that information already, but did you know there’s also a Jurassic World... | Read more »
SwitchArcade Round-Up: ‘Biomotor Unitron...
Hello gentle readers, and welcome to the SwitchArcade Round-Up for May 26th, 2022. The day is Thursday, and that means we’ve got a bunch of new releases to check out. Jumping into the past, we’ve got Biomotor Unitron and Arcade Archives Flipull,... | Read more »

Price Scanner via MacPrices.net

Memorial Day Apple iPad Sale: $30 off 9th-gen...
Apple reseller Expercom is offering a $30 discount on all 9th-generation 10.2″ iPads and a $75 discount on all 11″ M1 iPad Pros through June 6th as part of their Memorial Day Sale. Prices start at $... Read more
Memorial Day Weekend Savings: MagSafe accesso...
Amazon has Apple MagSafe Chargers and Apple’s MagSafe Battery on sale for up to $20 off MSRP as part of their Memorial Day Weekend Sale sale. Shipping is free. Amazon’s sale prices are among the... Read more
Best Memorial Day Weekend MacBook Deal: Get t...
Other World Computing has Apple refurbished, factory-sealed, current-generation 13″ Space Gray M1 MacBook Pros on sale for $420-$500 off Apple’s MSRP, starting at only $879. Their prices are the... Read more
Memorial Day Weekend iPhone Sale: $250 off iP...
As part of their Memorial Day Weekend sale, Xfinity Mobile is offering any new Apple iPhone 13, or the 64GB iPhone 12, for $250 off MSRP for customers switching to Xfinity Mobile and opening a new... Read more
Memorial Day Weekend iPhone Sale: Free $300 g...
Memorial Day Weekend iPhone sales are now live at Verizon’s low-cost wireless cell service, Visible. They will include a free $300 gift card with the purchase of a new 2022 iPhone 13 Pro Max, 13 Pro... Read more
In stock today: 13″ M1 MacBook Air for $899,...
B&H has Apple’s base 13″ M1 MacBook Air (Space Gray) in stock and on sale today for $100 off MSRP, only $899. Free 1-2 day shipping is available to most addresses in the US: 8-Core M1 Apple... Read more
In stock today: Open-box 16″ MacBook Pro with...
Having trouble finding a 16″ M1 Pro MacBook Pro to buy? QuickShip Electronics has open-box return 16″ M1 Pro MacBook Pros in stock and on sale for $500 off MSRP on their eBay store right now, each... Read more
16″ MacBook Pro with Apple M1 Pro CPU in stoc...
Stock of Apple’s 16″ MacBook Pro can be hard to find at resellers today. However, Apple reseller Expercom is reporting stock of the Silver 16″ MacBook Pro with a 10-Core M1 Pro CPU and 512GB SSD... Read more
Amazon has select 13″ M1 MacBook Airs on sale...
Amazon has select Apple 13″ M1 MacBook Airs on sale for $100 off MSRP today, only $899. Amazon does not have stock of these MacBooks, but they are available for order at the discounted price. The... Read more
Deal Alert! 14″ 10-Core M1 Pro MacBook Pros a...
Amazon has 14″ MacBook Pros with a 10-Core M1 Pro CPUs on sale today for $2249.99 shipped. That’s $250 off Apple’s MSRP. Amazon’s prices are the lowest currently available for 10-Core 14″ MacBook... Read more

Jobs Board

Certification Manager, *Apple* - DISH (Unit...
…data-driven self-starter to join the product development team for all Apple products concerning schedules, waiver and compliance requirements, device certification, Read more
Sr. Strategic Marketing Programs Manager - *...
The Sr. Strategic Marketing Programs Manager - Apple will be focused on helping SHI tell a compelling and exciting story around its partnership with Apple Read more
*Apple* Engineering Specialist - General Dyn...
…IT Service Delivery solutions to SEC. Currently, we are seeking an Apple Engineering Specialist in Washington, DC The responsibilities for candidates in this Read more
*Apple* Engineering Specialist - General Dyn...
…IT Service Delivery solutions to SEC. Currently, we are seeking an Apple Engineering Specialist in Washington, DC The responsibilities for candidates in this Read more
Sephora Beauty Advisor - *Apple* Blossom Ma...
Sephora Beauty Advisor - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.