multiple Find and Replace

Feature requests, and in-depth discussions of features and the way Mellel works

Moderators: Eyal Redler, redlers, Ori Redler

Post Reply
centralasian
Got the auto-title mojo working
Posts: 18
Joined: Wed Apr 11, 2007 9:47 pm
Location: Central Asia

multiple Find and Replace

Post by centralasian »

I have a document in one language which I want to transcribe into another, letter by letter. Thus far I do a Find a Replace for each letter.

Is there a way to script Mellel so that I can type in all the letters of the first language to be found and replaced by their equivalents in the other language? That way instead of 36 copy letter->Find->paste letter>tab->insert letter to replace found letter->return->repeat!, and then do the same for every document I need to do this on, I can type something up once and run all the docs through it.

Any thoughts? Thanks!
the best roads of all are the ones which aren't certain - bruce cockburn
nicka
Knows everything, can prove it
Posts: 677
Joined: Thu Oct 20, 2005 2:55 pm
Location: Oslo
Contact:

Re: multiple Find and Replace

Post by nicka »

You mean that you want to go from one script to another (not language)? So it is literally a one-to-one replacement of one character with another one?

If so, you can make a Find Action for each substitution, then make a Find Set which contains all the individual (36?) Find Actions. Then you can simply invoke that Find Set to change every character in a whole document.

There are three potential complications that I can see:

1) If there are characters which are in both the starting script and the target script, you will have to be very careful about what order the Find Actions are organised in, or may even need to use extra Find Actions which insert placeholders.

2) Find Sets work on whole documents, not selections, so you have to convert a whole document at a time. Obviously there is a workaround involving cut and paste into a new document and back, if necessary.

3) You'll need to do all of this again if you want to convert in the other direction.

Also, annoyingly, the Find Set dialogue is small and not resizable. Not a fatal problem, but it will get in your way a bit.
centralasian
Got the auto-title mojo working
Posts: 18
Joined: Wed Apr 11, 2007 9:47 pm
Location: Central Asia

Re: multiple Find and Replace

Post by centralasian »

Wow. I thought I looked everywhere. My mind however is still very much Nisus-oriented, and a FindSet concept never entered it! Thank you. You do know everything.
the best roads of all are the ones which aren't certain - bruce cockburn
nicka
Knows everything, can prove it
Posts: 677
Joined: Thu Oct 20, 2005 2:55 pm
Location: Oslo
Contact:

Re: multiple Find and Replace

Post by nicka »

You do know everything.
That is false... I think. Some people on this forum are much better qualified than me in that regard.

One thing I do know, that might be of use, is that Find Actions are stored inside your user folder in /Library/Application Support/Mellel/Find Actions/, and they are XML files that you can read with a text editor like TextWrangler.

You might find it quicker to create one Find Action that replaces (e.g.) 'α' with 'a', then copy the Find Action file thirty-six (?) times with different names (always ending in .findact) and replace the characters directly in the files, all the way to the final file which would have (say) 'ω' and 'o'.

Then back in Mellel (you have to quit and relaunch it), in the Find Set dialogue you should find thirty-six different Find Actions ready to be complied into one Find Set.

Warning: this is mucking about behind the scenes and may have weird results. But it could save quite a bit of time.
signinstranger
Knows everything, can prove it
Posts: 112
Joined: Sat Sep 02, 2006 12:53 pm
Location: Germany
Contact:

Re: multiple Find and Replace

Post by signinstranger »

Warning: this is mucking about behind the scenes and may have weird results. But it could save quite a bit of time.
A unix savvy person would probably tackle the raw .mellel/main.xml file with a shell script...
nicka
Knows everything, can prove it
Posts: 677
Joined: Thu Oct 20, 2005 2:55 pm
Location: Oslo
Contact:

Re: multiple Find and Replace

Post by nicka »

Not so easy, I think. How would you avoid finding and replacing characters that were not part of the text, but part of some XML tag, a style name or something like that? Wouldn't you have to write a script that could parse XML? (I may just be revealing my ignorance here, I know...)
signinstranger
Knows everything, can prove it
Posts: 112
Joined: Sat Sep 02, 2006 12:53 pm
Location: Germany
Contact:

Re: multiple Find and Replace

Post by signinstranger »

XML tags are always unambiguous, since they were made to be parsed :D

BTW: There's also a proper tool for such conversions, although I still haven't figured out how to parse .mellel files with it:

http://scripts.sil.org/TECkitDownloads
joewiz
Knows everything, can prove it
Posts: 199
Joined: Sun Oct 23, 2005 9:42 pm

Re: multiple Find and Replace

Post by joewiz »

nicka wrote:Not so easy, I think. How would you avoid finding and replacing characters that were not part of the text, but part of some XML tag, a style name or something like that? Wouldn't you have to write a script that could parse XML? (I may just be revealing my ignorance here, I know...)
Better than writing your own XML parser is to use XSLT (which lets you confine your operations to arbirary tags) and the XPath 'translate' function (which literally lets you replace characters in one string '0123456789' one-to-one with those of another 'abcdefghijk').

But findsets are also a powerful tool, so if they do the job, I'd go for that.
centralasian
Got the auto-title mojo working
Posts: 18
Joined: Wed Apr 11, 2007 9:47 pm
Location: Central Asia

Re: multiple Find and Replace

Post by centralasian »

Just to update... I ended up using the snazzy "Save Find Action...", and then making a FindSet out of them. Has saved me loads of time!
the best roads of all are the ones which aren't certain - bruce cockburn
Post Reply