[Date Prev][Date Next]
[Thread Prev][Thread Next]
[Date Index]
[Thread Index]
[New search]
To: Bill Briggs <web@xxxxxxxxxxx>, framers@xxxxxxxxxxxxxx (Framers List), framers@xxxxxxxxx
Subject: Re: set contents of cells by AppleScript
From: Larry Kollar <Larry.Kollar@xxxxxxxxxxx>
Date: Fri, 16 Feb 2001 12:43:13 -0500
In-Reply-To: <p0433010db6b2ecfeff1f@[192.168.0.3]>
References: <LYRIS-25651-7678-2001.02.13-13.35.46--web#nbnet.nb.ca@lists.frameusers.co m> <LYRIS-25651-7678-2001.02.13-13.35.46--web#nbnet.nb.ca@lists.frameusers.com>
Sender: owner-framers@xxxxxxxxx
Bill Briggs wrote: >>The following snippet appends " hi" to the text of each cell in >>the selection.... > I think your code works fine. But it was not clear from the original >post if the person wanted to delete the original text and replace it, >or just add to it. And if it's multi-paragraph text in the cell, what >he wanted to do with that. True. My intent was to show him how to get the changed text back into the right cell after changing it. Tacking a short string to the end of the text was there mainly as a placeholder. > One other oddity that is exhibited in this script. Once you make a >change to the first cell of the selection, the selection disappears. >If you select the range manually as was assumed in Larry's script, >then you need to use the reference form he did to assign the >selection to a variable. If you make the selection in the body of the >script based on some calculation, then you can use this kind of >approach to "retain" (actually re-select) the cells within the >script. It's a bit goofy, but it works with no problem. You can use "select myCells" to restore the selection as well. The Perl enthusiasts have a saying: "there's more than one way to do it." :-) Making the selection programatically allows for batch processing; selecting the text & then running the script over the selection is better for interactive use. Here's a slightly revised version of my original script; I've bummed out the inner "tell" (which seems to have given the script a significant speed boost), added some error checking, and restored the original selection. (The "‚" is a not-equals character, just in case it doesn't show up right in some mailers.) tell application "FrameMaker+SGML 6.0" -- Abort if the selection isn't part of a table. if (selection class of active document) ‚ table range then display dialog "You must select one or more table cells." tell me to quit -- if saved as an application end if set myCells to (selection of active document) -- or document 1 (* Manipulate each cell of the selection. We pull the text into a list to make it easy to get at if needed. Cast myData as a list even if only one cell is selected. *) set myData to (get text of myCells) as list set n to (count myData) -- get # of cells repeat with i from 1 to n -- do something to (cell i of myCells) end repeat -- Restore the selection select myCells end tell -- end of script I have to keep reminding myself that Adobe fixed a LOT of bugs in Frame's AppleScript support from 5.5.1 to 6.0; I don't have to always use nested "tell" constructs to get something done. Larry ** To unsubscribe, send a message to majordomo@omsys.com ** ** with "unsubscribe framers" (no quotes) in the body. **