Chapter w2: Ragtime for HTML and Images

You're probably wondering if anyone has produced a really complete scriptable and recordable commercial graphics application. You're not alone in that thought. There are two such products on the market as of the writing of this book: Multi-Ad Creator2 and B&E RagTime. Both are extremely powerful and useful applications, though neither has a large installed user base. Two other scriptable graphics applications exist. Web Collage, which produces graphics specifically for the Web, and PhotoScripter, which makes Photoshop 5.0 fully scriptable.

We'll first take a look at RagTime. The German software company B&E has sold this program in Europe for some time now. It has just recently hit the American market and comes equipped with some very impressive AppleScript abilities. It is actually a complete document-management tool with word processing, spreadsheet, and drawing capabilities all integrated and all equally scriptable.

Scripting RagTime

RagTime is fully scriptable and recordable. The fact that it's scriptable means that we can control essentially every function of the application. The fact that it's recordable means a whole lot more: The application itself will generate usable AppleScript for us, based on our actions!

RagTime offers a concise and clear object-model dictionary for dealing with graphics objects of all types. Every graphic shape is has its own noun (object) in the dictionary. Verbs (commands) affect the nouns in a consistent way.

RagTime is so complete, it does unexpected things like save the pages in your document as a JPEG image-based series of HTML files. Your scripts can also generate faxes directly from the application. Figure w2.1 shows the dictionary entries for these more unusual capabilities.

Figure w2.1. RagTime's dictionary entries for generating faxes and HTML

Recording and modifying RagTime scripts

RagTime's dictionary has that special beauty and elegance exhibited only by a fully recordable application that speaks true object-model AppleScript. Our first order of business will be to experience the grace of good script recording.

Recording your actions is a great way to learn the syntax for AppleScripting RagTime. Once you have recorded some useful scripts in RagTime, you can edit them in the Script Editor and make them more flexible by replacing numeric values with variables.

To record activities in RagTime:

  1. Launch RagTime by double-clicking its application icon. A new document window should appear.

  2. Now switch to the Script Editor and create a new document.

  3. Press the Record button in your new document window.

  4. You're now ready to select a drawing tool and begin creating and modifying objects of your choosing.

  5. Once you've created and modified a few objects, bring the Script Editor to the front and press the Stop button. What you see should be similar to Figure w2.2.

  6. Take some time to get comfortable with manual object creation and modification in RagTime before proceeding.

Figure w2.2. A script recorded from a user's object creation and modification activities in RagTime 4

Creating and exporting graphics and text

RagTime supports the creation of new documents and individual graphic elements via scripting. The script shown in Code w2.1 creates a new document, clears it, and then creates a yellow rectangle with red text on it before exporting the object as a PICT file. PICT is the only native export format RagTime supports, so you'll need to batch process exported images in another program to get your files in GIF or JPEG format. Figure w2.3 shows the document created by this script.

To create and export graphics and text as a PICT file:

  1. tell application "RagTime 4"
          activate

    We begin speaking with RagTime and bring it to the front.

  2. make new document at end

    Then we create a new document.

  3. select rectangle 1 of page 1 of layout "Layout 1" of document 1
         delete selection

    Next we select the default object that is automatically created and delete it.

  4. set myObject1 to (make new rectangle at beginning of page 1 of layout "Layout 1" of document 1 with data {50, 110, 550, 210})
          set color of fill of myObject1 to {65535, 65535, 0}

    Now we create a new rectangle with coordinates 50,110 for top left and 550,210 for bottom right. RagTime returns a reference to this object that we store in myObject1. We then use the reference to set the color of the rectangle to yellow (maximum red, maximum green, no blue). Colors are defined by a list of values in the form {red,green,blue} ranging from 0 to 65535.

  5. set myObject2 to (make new graphic text at beginning of page 1 of layout "Layout 1" of document 1 with properties
          {definition rect:{75, 125, 525, 175}})

    Next we create a text box with coordinates 75,125 for top left and 525,175 for bottom right. We store the reference to this object in myObject2.

  6. set fill style sheet of fill of myObject2 to "Transparent"
          set font of myObject2 to "Impact"
          set size of myObject2 to 36.0
          set text of myObject2 to "About the Company"
          set color of text of myObject2 to {65535, 0, 0}

    Now we set the fill style to transparent, the font to Impact, the point size to 36, the text to "About the Company", and the text color to maximum red, without any green or blue.

  7. select {myObject1, myObject2}
    save selection in myFile converting to "PICT"
    end tell

    Finally we select both objects and export the selection as a PICT file to our user-defined new file.

Code w2.1 . This script creates a new document, draws a yellow rectangle with red text on it, and then exports the objects as a PICT file.

set myFile to (new file)
tell application "RagTime 4"
activate
make new document at end
select rectangle 1 of page 1
of layout "Layout 1" of document 1
delete selection
set myObject1 to (make
new rectangle at beginning
of page 1 of layout "Layout 1"
of document 1 with data
{50, 110, 550, 210})
set color of fill of myObject1
to {65535, 65535, 0}
set myObject2 to (make
new graphic text at beginning
of page 1 of layout "Layout 1"
of document 1 with properties
{definition rect:
{75, 125, 525, 175}})
set fill style sheet of fill of
myObject2 to "Transparent"
set font of myObject2 to "Impact"
set size of myObject2 to 36.0
set text of myObject2 to
"About the Company"
set color of text of myObject2
to {65535, 0, 0}
select {myObject1, myObject2}
save selection in myFile
converting to "PICT"
end tell

Fig. w2.3  The document window in RagTime as it appears when the script is finished.

Faxing a document from RagTime

This script (Code w2.2) uses RagTime's built-in fax modem integration to fax the frontmost document. You could use this to create custom documents from a form-driven CGI and then fax them to a recipient, thereby creating a fax-on-demand CGI for your Web site. Figure w2.4 shows the active document in RagTime to be faxed by the script.

To fax a document with RagTime:

  1. tell application "RagTime 4"
         activate

    We start talking to RagTime and bring it to the front.

  2. fax window 1 fax number "1-510-555-5645" recipient "Ethan Wilde" company "Mediatrope" with print a copy without dialog, substitute fonts and show print dialog for copy
    end tell

    Now we tell RagTime to fax the frontmost window to 510-555-5645, placing the information regarding the recipient ("Ethan Wilde") and company ("Mediatrope") on the fax header. We specify to fax the window without displaying any dialogs by specifying without dialog and show print dialog or allowing for font substitution by specifying without substitute fonts.

Code w2.2. This script faxes the frontmost document without showing a dialog.

tell application "RagTime 4"
         activate
         fax window 1 fax number 
         "1-510-555-5645" recipient 
         "Ethan Wilde" company 
         "Mediatrope" with print 
         a copy without dialog, 
         substitute fonts and 
         show print dialog for copy
         end tell



Fig. w2.4  The faxSTF fax progress windows as it sends our fax from RagTime. RagTime will use the fax software you have installed to send faxes.

Faxing a document from RagTime

This script (Code w2.2) uses RagTime's built-in fax modem integration to fax the frontmost document. You could use this to create custom documents from a form-driven CGI and then fax them to a recipient, thereby creating a fax-on-demand CGI for your Web site. Figure w2.4 shows the active document in RagTime to be faxed by the script.

To fax a document with RagTime:

  1. tell application "RagTime 4"
         activate

    We start talking to RagTime and bring it to the front.

  2. fax window 1 fax number "1-510-555-5645" recipient "Ethan Wilde" company "Mediatrope" with print a copy without dialog, substitute fonts and show print dialog for copy
    end tell

    Now we tell RagTime to fax the frontmost window to 510-555-5645, placing the information regarding the recipient ("Ethan Wilde") and company ("Mediatrope") on the fax header. We specify to fax the window without displaying any dialogs by specifying without dialog and show print dialog or allowing for font substitution by specifying without substitute fonts.

Code w2.2. This script faxes the frontmost document without showing a dialog.

tell application "RagTime 4"
         activate
         fax window 1 fax number 
         "1-510-555-5645" recipient 
         "Ethan Wilde" company 
         "Mediatrope" with print 
         a copy without dialog, 
         substitute fonts and 
         show print dialog for copy
         end tell



Fig. w2.4  The faxSTF fax progress windows as it sends our fax from RagTime. RagTime will use the fax software you have installed to send faxes.

Saving a document as HTML

RagTime's ability to save as HTML is implemented in an unusual fashion. When you save your document as HTML, RagTime actually creates a separate JPEG image for each page in your document. Then RagTime creates an HTML page to display the image and a table of contents HTML file to link to each page. It then creates a parent frame so that the whole folder of exported files is displayed in a set of HTML frames. Since the content of each page is actually saved as a JPEG, all text and graphics are rasterized into the single JPEG image. This script (Code w2.3) saves the frontmost open RagTime document as HTML. Figure w2.5 shows a sample of HTML generated by RagTime.

To save a document as HTML:

  1. tell application "RagTime 4"
         activate

    We start talking to RagTime by bringing it to the front.

  2. print to HTML window 1 with dialog box shown, table of contents and navigation icons
    end tell

    Then we issue the print to HTML statement for the frontmost window, displaying a dialog to prompt the user for a folder name. The attribute table of contents has RagTime create a master table of contents index HTML file with links to all other pages created. Specifying navigation icons has RagTime use icons for navigation buttons in the HTML files created.

Code w2.3. This script saves the frontmost open document as HTML.

tell application "RagTime 4"
activate
print to HTML window 1
with dialog box shown,
table of contents and
navigation icons
end tell



Fig. w2.5  The HTML files generated by this script have a frame-based layout.