simple sort in Appleworks

I am a true novice to Applescript, and am trying to write a simple script to sort a range in a spreadsheet, but can’t seem to get past some real basics. I’m not sure I’m understanding the examples in the Appleworks library… Here’s what I’ve written… what do I need to change to get the script to run?

tell application “AppleWorks 6”
sort [a6 - m22]
vertical
{“a1”, ascending}
end tell

I’m sure there are some obvious errors here… I’m not sure of the syntax for the range… how to indicate a vertical sort, etc.
Thanks for any help for this neophyte!!

Model: eMac
AppleScript: 2.1.1
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

john:

Try this script:

tell application "AppleWorks 6"
	tell spreadsheet layer of front document
		sort with data {"c1", ascending}
	end tell
end tell

Essentially, this sorts on column C, while preserving all the row integrity with A&B.

This next script will sort the same way, but if any two items in C column are the same, B will be examined next:

tell application "AppleWorks 6"
	tell spreadsheet layer of front document
		sort with data {{"c1", descending}, {"b1", descending}}
	end tell
end tell

You can mix up the ascending versus descending in these combined sorts, depending on how you want your data arranged.

Good luck,

thanks so much for your reply!! I tried your solution, however I experienced a problem… I want to start the sort with the cell A3 rather than A1. When I ran your suggestion, I changed “a1” to “a3”, but it still starts the sort with cell A1 rather than cell A3. Suggestions?? Thank you so much!

Try this out:

tell application "AppleWorks 6"
	tell spreadsheet of front document
		set aa to object specifier of (cells "c3" thru "c10")
		sort aa with data {"c3", ascending}
	end tell
end tell

I admit that I do not fully understand the code, but it seems that in order to sort just a part of the column (or row, I suppose), you must first identify that section using the poorly explained object specifier property. Anyway, once that is set to a variable, you can use the general sort function using the specified data alone. Understand that this will NOT preserve relationships with columns A & B unless you select that data as well when you set the variable:

tell application "AppleWorks 6"
	tell spreadsheet of front document
		set aa to object specifier of (cells "a3" thru "c10")--This selects a bigger chunk of the sheet
		sort aa with data {"c3", ascending}--And still sorts by the C column
	end tell
end tell

I hope this is closer to what you are lookin for.

Thank you so much!! It’s working just the way i wanted!!:smiley: