Skip to main content
Inspiring
November 11, 2008
Question

Single line find/change command?

  • November 11, 2008
  • 2 replies
  • 302 views
I have to create a complex find/change AppleScript script with hundreds of text conversions, for which the following syntax seems bulky and awkward, at least in contrast to earlier scripting languages:

set find what of find text preferences to "c`"
set change to of change text preferences to "ĉ"
change text

Does anyone know of a way to get this on a single line?

Thanks,
Roy McCoy
This topic has been closed for replies.

2 replies

Roy McCoyAuthor
Inspiring
November 11, 2008
Shane Stanley wrote:

>> Does anyone know of a way to get this on a single line?
>
> You can't.

Okay, now I know, thanks.

> You can do it in two:
>
> set properties to {find text preferences:{find what:"c`"}, change text
> preferences:{change to:"Ä"}}
>
> But really, why bother?

Because I think that's going to be easier to edit and possibly less
prone to error than with long, comma-delineated lists of find and
change terms.

> If you have hundreds of them, put it in a loop:
>
> set theFinds to {"c`",...}
> set theChangess to {"Ä",...}
> repeat with i from 1 to count of theFinds
> set find what of find text preferences to (item i of theFinds)
> set change to of change text preferences to (item i of theChanges)
> change text document 1
> end repeat

That's certainly elegant, thanks. I'll probably use it for some
routines - ironically, the shorter ones for which I don't need a more
concise format so much.


Roy McCoy
Inspiring
November 11, 2008
On 12/11/08 8:33 AM, "Roy McCoy" <member@adobeforums.com> wrote:<br /><br />> Does anyone know of a way to get this on a single line?<br /><br />You can't. You can do it in two:<br /><br />set properties to {find text preferences:{find what:"c`"}, change text<br />preferences:{change to:"Ä"}}<br /><br />But really, why bother? If you have hundreds of them, put it in a loop:<br /><br />set theFinds to {"c`",...}<br />set theChangess to {"Ä",...}<br />repeat with i from 1 to count of theFinds<br />set find what of find text preferences to (item i of theFinds)<br />set change to of change text preferences to (item i of theChanges)<br />change text document 1<br />end repeat<br /><br />-- <br />Shane Stanley <sstanley@myriad-com.com.au>