|
AppleWorks Scripting Problems |
|
2002.09.15 |
http://www.barefeetware.com /appleworks/problems/ |
|
Good, |
AppleWorks has a rich AppleScript dictionary. However, there are a few problems with the AppleScript support (especially in AppleWorks 5) that require some particular work arounds or which prevent some functions altogether. |
|
AppleWorks 5 |
In AppleWorks 5, much of the features offered by the dictionary were not actually supported, which we define as a hole. This lead to great frustration and guesswork. This page lists the common occurrences. Thankfully, AppleWorks 6 has few such holes. |
|
Trouble Shooting |
For information on running (not writing) prepared scripts, compatibility problems and some fixes, see our troubleshooting page for the Enhancement Pack set of scripts. |
|
Accessing Spreadsheet FrameProblem in AppleWorks 6.2.4 (and some earlier?) on Mac OS X (and 9?)Work Around
You should be able to (and it used to work) get a reference to the visible records in a database with:
every record of database of front document whose visible is true
but it returns the hidden records.
Ask for the records that are not invisible:
every record of database of front document whose visible is not false
Call Built in OperationsProblem in AppleWorks version: 5 and 6?Work Around
Following the AppleWorks AppleScript dictionary, for a floating spreadsheet in a word processing doc, the required syntax is:
tell application "AppleWorks"
tell spreadsheet of spreadsheet frame 1 of drawing area of document 1
set cell "A1" to "1234"
end tell
end tell
The above works.
For an in-line spreadsheet (ie like a character in the text), the dictionary suggests that the syntax should be:
tell application "AppleWorks"
tell spreadsheet of spreadsheet frame 1 of drawing area of character 1 in text body of document 1
set cell "A1" to "1234"
end tell
end tell
but that fails.
Can probably work around it by scripting a copy and paste of the frame, change it, then paste back.
RefreshingProblem in AppleWorks versions: 5 & 6
Need to be able to call built in buttons. do script does not work for buttons such as New URL Link, Make Table.
Macro Function UppercaseAppropriate refreshing should be done when a script affects objects, after the script has completed.
There are many instances, including:
- A text frame does not reposition the characters when AppleScript changes the font size.
- A database list is not redrawn when records are deleted.
Macro Function Numeric ParameterProblem in AppleWorks versions: 5 & 6
A spreadsheet cell or database field can contain the MACRO function to call an AppleScript. The general format is =MACRO(<script file name>, 2, <procedure name>, <data1>, <data2>, etc). It works fine, but fails if <procedurename> contains any uppercase letters.
Elements in SelectionProblem in AppleWorks version 5, fixed in 6.
If a data parameter refers to a cell or field which is not text (such as numeric), the MACRO function has to coerce it to text with something like: 'A1'&"" or NUMTOTEXT('A1').
Selected Text in FieldProblem in AppleWorks version 5, fixed in 6.
In most cases it is difficult to address specific items within the selection. For example, the following fails:
item 1 in selection -- where multiple graphic objects are selected
DocumentProblem in AppleWorks version 5 and 6.
Cannot address the selected text in a database field.
Page NumberProblem in AppleWorks version 5, fixed in 6.
The file property fails if the document was opened with read only permission (eg on a file server). Most of the properties of a document fail. See the dictionary page.
Text Nested ElementsProblem in AppleWorks version 5, fixed in 6.
There is no way to get the page of an object or the content of a particular page.
User StylesProblem in AppleWorks version 5, fixed in 6.Work Arounds
A reference to an object three levels deep, fails. eg character 2 in paragraph 3 in text body.
Two work arounds are possible:
- Copy the text to a temporary document. This is especially convenient when the outer object is the current selection. It has the advantage of also allowing the user to undo the final paste to revert to the state before the script was run.
select paragraph 3 in text body...
copy to clipboard
make new document at front
paste
character 2 in text body of front document
- Calculate the character number to remove the middle object reference.
set charN to offset of paragraph 3
character charN + 2
Check SpellingIn AppleWorks 5, name property of user style is incorrectly "Untitled xx" rather than the actual name of the style.
AppleWorks 6 removed the user style property and introduced paragraph style. It provides just the name of the style. AppleWorks 6 offers no way to access the other user styles such as styles of characters and graphic objects
SpeakAppleWorks 5 provided a check spelling event:
check spelling
[of reference] -- the object or text to spell-check
[dialog boolean] -- display a dialog showing the misspelled words?
Result: list] -- list of misspelled words
The reference would fail for a reference to an AppleWorks object, such as text body of front document. It would accept a text object, so you could simply coerce like (text body of front document) as text.
AppleWorks 6 removed the check spelling event altogether, with no replacement.
HeaderProblem in AppleWorks version 6, OK in 5.Work Around
The speak event will only accept a reference to an AppleWorks object, such as text body of document, but wont accept literal text, such as hello or an expression such as hello & word 5 in text body.
The standard scripting additions should include a say command. So use speak for any AppleWorks objects and say for literal text or expressions (including those involving AppleWorks objects).
Nested property referenceProblem in AppleWorks version 5, fixed in 6?Work Around
Accessing text properties of a header will crash the computer. eg font of character 1 in header of front document. It will crash even if the text in the header is selected and the properties of the selection are manipulated.
AppleScript can set some text properties of the selection by selecting menu items, eg select menu item "Bold" in menu "Style". So, if the selection is in the header, the header can be indirectly manipulated. Selecting the header is not easy. The simplest way is to create the header which places the cursor in it. In some circumstances a macro called by "do script" might work.
This fails:Often need to set up a temporary variable to reference a nested property.examples
This fails:This works:
<property> of user style of...
set myStyle to user style of...
<property> of myStyle
Field ValueProblem in AppleWorks version 5, fixed in 6.This works:
Cannot use the every operator as expected.
This fails:
repeat with thisParagraph in every paragraph
set paragraphCount to count every paragraph
repeat with paragraphN from 1 to paragraphCount
set thisParagraph to paragraph paragraphN
Need to be able to use form field <fieldname> to allow field names to be determined by variables.Problem in AppleWorks version 5, fixed in 6?This works:
Cannot set the value of a field.
Need weird syntax to get value of a field.
This fails:
field <fieldname> of myRecord
<fieldname> of myRecord - if <fieldname> is not a reserved word
|<fieldname>| of myRecord - if <fieldname> is a reserved word
graphic objectAppleWorks 5 cannot make fields. AppleWorks 6 can, except for calculated fields.
chartProblem in AppleWorks version 5, fixed in 6.Events
Various properties fail, including fill color, fill pattern, fill gradient, fill texture, pen pattern etc.
duplicate: fails
exists: returns true if exists but returns error if doesn't exist
make: fails for new spreadsheet frame, text frame, paint frame. Makes a rectangle.
make: must specify properties with at least one label and value, but only bounds will actually work.
make: Accepts at front, at end or at back, but still makes at front.
move: fails
movieProblem in AppleWorks version 5, fixed in 6.
Using "chart" in a script compiles as "chart legend". Discovered by Dennis Tokaryk, 1999.10.30.
polygonIn AppleWorks 5, all properties fail.
AppleWorks 6 can manipulate a movie as a graphic object (eg adjust bounds), but no specific movie properties.
text frameIn AppleWorks 5, polygon (also used for a bezier) is made up of vertices. But all properties of the vertex fail.
AppleWorks 6 can make a polygon with data {{x1,y1}, {x2,y2} etc}, but cannot adjust or read existing polygons. AppleWorks 6.0 and 6.0.3 makes a phantom point at the end of a polygon.
cellIn AppleWorks 5, make new text frame fails, producing a rectangle instead. In AppleWorks 6 it works but if bounds are not specified, it spans 42 pages! Fixed in AppleWorks 6.0.3.
sort cellsProblems in AppleWorks version 5, fixed in 6.
When asked for cell 1, there is no problem. But a request for cell 2 (or cell {2,1}) will return cells 2 and 3. A request for cell 3 will return cells 3, 4 and 5. To work around this bug, just prefix these references with "cell 1 in", such as "cell 1 in cell 3 in..."
Reference to cells by alpha numeric grid, eg cell "A1", works OK.
Cannot set the formula of a cell, but can set the cell itself to be the formula (ie set cell "A3" to "=A1+A2").
If the formula contains a reference to a cell past the Z column, AppleWorks will crash. eg "=SUM(AA45..AA55)"
AppleWorks 5 has trouble "coercing" numbers to text. If you look at AppleWorks 5 AppleScript dictionary, the formula of a cell is of class "text". However, you would assume that given a number, AppleWorks would happily coerce it to text. Unfortunately, in this case, it converts it to some kind of text style, such as set cell "A1" to 2, instead inserts the text "ital". If you want to force the correct coercion, you use the "as" operator. For instance, 2 as text is "2".
AppleWorks 5 and 6.0 had problems setting a cell border (such as left border) to false, having the side affect of enabling the three other borders. This bug is fixed in 6.0.3.
In AppleWorks 5, the sort event (for cells in a spreadsheet) does not work at all.
In AppleWorks 6.0:
sort reference -- the cell range to sort
[with orientation horizontal/vertical] -- sort horizontally (swap columns), or vertically (swap rows) [default is vertical]
[with data a list of list] -- names and directions on which to sort e.g. {{"A1",descending},{"B1",ascending}} [default is upper-left cell, ascending]
horizontal sorts vertical and vertical sorts horizontal. ascending and descending both sort descending, so there is no way to sort ascending.
Contributed by Vincent Jalby 2000.03.01.
This bug is fixed in AppleWorks 6.0.3.
.More soon