Hi all,
Long-time reader, first time poster. I'm and editor with a British publishing house, so I'm not a coder by trade and I generally find the help I need by pillaging various forums.
I recently began using AppleScript to automate the most repetitive editorial changes our department makes to Word (or QuarkXpress) files as we format documents for publication. The script I've written is a very basic find/replace that gets the material from the American English of many of our analysts, into British English (the language of our brand). The script also fixes some random formatting choices we make changing things like "6 million" into "6m", or "5 percent" into "5%", etc.
It feels exceedingly clunky and inelegant, and I hope to improve that at some point. Still, the script has reduced my work load immensely and enabled me to focus more on factchecking (what I feel is the more important of my editorial responsibilities.
I'd like to ask for advice on one specific obstacle. To get text into proper British spelling, I have to wage war on the letter "Z", and the script I've copied below shows how I go about changing all instances of "ize", "ization", and "yze" into their British counterparts with "s". Things like "specialize" become "specialise" and so forth. As an American myself, this feels like a tragic shift every time it is made, and scripting it has somewhat reduced my daily pain, in this regard.
One sticking point persists: the word "size", which is spelled the same in both dialects. I included a contingency to fix all instances of " sise " so that it could be recovered after being altered by the other script, but this has, so far, failed to work. If the script changes the word "size" to "sise" using the "ize" to "ise" shift, it seems unable to recognize " sise " as an independent word and change it back. However, if I test a text with " sise ", it will identify the offense and amend it to "size". Thus, I'm a bit confused as to where the problem lies.
Any suggestions on how I can fix this? I've tried to reduce the code below, so that the most relevant bits are present. My comments are included, because I get quickly bewildered when looking at long sections of code and forget what I'm doing. I have many other question, (namely, how to make this prettier) but I would prefer to focus on this for now.
I appreciate any and all comments/suggestions, just please remember that I've been at this for all of two weeks, with no prior coding experience, so be forgiving.
Cheers,
-s
Long-time reader, first time poster. I'm and editor with a British publishing house, so I'm not a coder by trade and I generally find the help I need by pillaging various forums.
I recently began using AppleScript to automate the most repetitive editorial changes our department makes to Word (or QuarkXpress) files as we format documents for publication. The script I've written is a very basic find/replace that gets the material from the American English of many of our analysts, into British English (the language of our brand). The script also fixes some random formatting choices we make changing things like "6 million" into "6m", or "5 percent" into "5%", etc.
It feels exceedingly clunky and inelegant, and I hope to improve that at some point. Still, the script has reduced my work load immensely and enabled me to focus more on factchecking (what I feel is the more important of my editorial responsibilities.
I'd like to ask for advice on one specific obstacle. To get text into proper British spelling, I have to wage war on the letter "Z", and the script I've copied below shows how I go about changing all instances of "ize", "ization", and "yze" into their British counterparts with "s". Things like "specialize" become "specialise" and so forth. As an American myself, this feels like a tragic shift every time it is made, and scripting it has somewhat reduced my daily pain, in this regard.
One sticking point persists: the word "size", which is spelled the same in both dialects. I included a contingency to fix all instances of " sise " so that it could be recovered after being altered by the other script, but this has, so far, failed to work. If the script changes the word "size" to "sise" using the "ize" to "ise" shift, it seems unable to recognize " sise " as an independent word and change it back. However, if I test a text with " sise ", it will identify the offense and amend it to "size". Thus, I'm a bit confused as to where the problem lies.
Any suggestions on how I can fix this? I've tried to reduce the code below, so that the most relevant bits are present. My comments are included, because I get quickly bewildered when looking at long sections of code and forget what I'm doing. I have many other question, (namely, how to make this prettier) but I would prefer to focus on this for now.
Code:
tell application "Microsoft Word"
-- choose a file and open it
set theFile to choose file with prompt "Select a document:"
open theFile
read theFile
-- change language
set language ID of selection to english uk
-- simple find/replace for American to British spelling
execute find (find object of myRange) find text "labor" replace with "labour" replace replace all
execute find (find object of myRange) find text "ize" replace with "ise" replace replace all
execute find (find object of myRange) find text "izing" replace with "ising" replace replace all
execute find (find object of myRange) find text "ization" replace with "isation" replace replace all
execute find (find object of myRange) find text "yze" replace with "yse" replace replace all
execute find (find object of myRange) find text " sise " replace with " size " replace replace all
end tell
I appreciate any and all comments/suggestions, just please remember that I've been at this for all of two weeks, with no prior coding experience, so be forgiving.
Cheers,
-s