• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Pages 2.0 Scripting
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Pages 2.0 Scripting


  • Subject: Re: Pages 2.0 Scripting
  • From: Scott Lindsey <email@hidden>
  • Date: Tue, 17 Jan 2006 14:14:37 -0800

Bruce Robertson wrote:

I see that Pages 2.0 is scriptable, and I hope we'll see examples soon. I
have begun poking around but don't have anything to show yet. I'm
particularly interested in charting. I can't yet figure out how to get and
modify the data of an existing chart.

The dictionary for Pages 2.0 does a pretty good job of documenting the functionality.  Note the Pages-specific suites, especially the Pages Text Suite.  While the Standard and Text suites do appear in the dictionary, this is primarily a side-effect.  The terminology in the Pages suites should be given precedence.

As for charts (and tables), support for those types of objects is somewhat limited in this release.  Note the add chart and add table commands, similar to Keynote's add chart command.  These can be used to create objects of these types, but there isn't full support for get and set of these objects' properties, particularly their underlying data.  Because charts and tables are graphic objects, their graphic properties can be manipulated as per the Pages Graphics Suite.

Pages' scripting model is similar to that of ClarisWorks/AppleWorks, but there are differences.  Here's a few basic,  yet illustrative snippets of my own; hope they're useful:

tell application "Pages"
make new document with properties {template name:"Classic Letter"}
tell body text of document 1
delete (paragraphs 19 thru 21) -- Letter body placeholder text
make new text at after paragraph 18 with data "This is the content of my letter.  Should you choose to reply to this letter, please do so at your convenience." & return & "Etc., etc., and furthermore." & return
set paragraph 12 to "John Smith" & return
set paragraph 13 to "Major Domo" & return
set paragraph 14 to "Acme Widgets" & return
set paragraph 15 to "1234 Second Street" & return
set paragraph 16 to "Uptown USA" & return
set paragraph 18 to "Dear John," & return


delete (paragraphs 5 thru 9) -- Unwanted address fields
end tell
end tell


tell application "Pages"
make new document with properties {body text:"Hello world, how are you?"}
tell document 1
set theStyle to a reference to character style "Emphasis"
tell body text
set character style of word 2 to theStyle
set character style of word 4 to theStyle
set underline type of word 3 to single underline
end tell
set color of theStyle to {65535, 0, 0}
end tell
end tell


tell application "Pages"
tell (make new document with properties {body text:"Here is some sample text."})
make new shape at after word 3 of body text with properties {shape type:oval, name:"My oval"} -- inline
make new shape with properties {shape type:star, name:"My star"} -- floating
tell body text
make new paragraph at end with data "A second paragraph."
make new paragraph at before last paragraph with data "A third paragraph, created before the second one."
set object text of shape 1 to "hi there" -- shape 1 of body text, the oval.
end tell
set object text of shape 1 to "bye now" -- shape 1 of document, the star.


set shadow of shape "My oval" to true
set shadow color of shape "My oval" to {25000, 0, 65535}
set fill color of shape "My star" to {65535, 0, 25000}
end tell
end tell

tell application "Pages"
set ruler units to centimeters
tell (make new document at front with properties {template name:"Blank"})
add chart row names {"A", "B"} column names {"Widgets", "Doorknobs", "Elephants"} ¬
data {{1, 2, 3}, {4, 5, 6}} type "horizontal_bar_3d" group by "column"
tell graphic 1
set width to 5.0
set height to 5.0
end tell
tell graphic 2
set width to 2.0
set vertical position to 8.0
set horizontal position to 7.0
end tell
end tell
end tell


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Pages 2.0 Scripting
      • From: Bruce Robertson <email@hidden>
  • Prev by Date: Quicktime Player control over multiple windows/movies
  • Next by Date: formatting text in preferences won't save
  • Previous by thread: Pages 2.0 Scripting
  • Next by thread: Re: Pages 2.0 Scripting
  • Index(es):
    • Date
    • Thread