Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Search CAPITALISED words and replace with smallcaps: how? Scripting?

141 views
Skip to first unread message

wa veghel

unread,
Mar 8, 2003, 10:33:23 AM3/8/03
to
A publication made in QXPress is now transfered to InDesign.

In QXPress we used a Xtension called 'Acronym convert' that automatically searched words TYPED in capital NOT 'styled capital'(!!)

We can give the number of characters, say any word in capitals with more than 2 characters), replaced this words with lowercase and then made them SmallCaps. After that we could search with QXPress' build in Find&Replace for the style smallcaps and replace that with a characterstyle that used a 'Expert Fonts' with real smallcaps and track +10 (in InDesign this would be +50).

As this is a publication that has LOTS of this acronyms, we are looking for a way to do this in InDesign. Searching and replacing 'by hand' would take way to much time.

So our question is:
- Is there a way to search for words TYPED in capitals (NOT style capital!!!)?

And is there maybe a way to search, replace with lowercase and then apply SmallCaps, all in one go?
We are not familiar with scriting ourselfs, so any suggestions (and 'manuals' ;-) ) are very welcome.

I thank in advance all that can help us here!

wa veghel

unread,
Mar 8, 2003, 11:11:52 AM3/8/03
to
By the way: there was a Apple script once placed in this forum but that simply did not work...

Buko

unread,
Mar 8, 2003, 11:26:00 AM3/8/03
to
Ole is the one that can help you here I'm not that good at scripting myself.

BTW how is the HP printer problem? did you solve it?

wa veghel

unread,
Mar 10, 2003, 9:09:57 AM3/10/03
to
Ah, Buko. Been a ling time.

BTW how is the HP printer problem? did you solve it?


No, still only ASCII...

Jay Fraser

unread,
Mar 11, 2003, 1:28:36 PM3/11/03
to
You can do it, but it'd be really, really slow. You'd have to check the ascii number of the second letter of every word to see if it's in the range 65-90. That's the slow part. Then you can select the word, convert it to lower case & apply a "small caps" character style fairly easily.

My inDesign mac is grinding its way through a long script right now, or I'd see if I could do it.

Of course, if you post your request in the inDesign scripting forum, Ole or Shane Stanly will probably come up w/ something a lot more quick & elegant.

Olav Kvern

unread,
Mar 11, 2003, 3:11:05 PM3/11/03
to
Gang--

Here's the script I sent to Wilma (Jay's right--it *is* slow):

--ChangeAllCapsToSmallCaps.scpt
--An InDesign 2.0 script
--Changes all of the text that has been typed as ALL CAPS
--(i.e., not formatted using the All Caps case option)
--to the Small Caps case option.
--
--The variable "myLowerLimit" sets the minimum word length--if the
--word is shorter than the value of this variable, it will be ignored.
set myLowerLimit to 2
tell application "InDesign 2.0.2"
tell active document
--Create the "SmallCaps" character style if it does not already exist.
try
set myCharacterStyle to character style "SmallCaps"
on error
set myCharacterStyle to make character style with properties {name:"SmallCaps", tracking:50, capitalization:small caps}
end try
repeat with myStoryCounter from 1 to (count stories)
set myStory to object reference of story myStoryCounter
tell myStory
repeat with myParagraphCounter from 1 to (count paragraphs)
set myParagraph to object reference of paragraph myParagraphCounter of myStory
repeat with myWordCounter from 1 to (count words of myParagraph)
set myWord to object reference of word myWordCounter of myParagraph
if (count characters of myWord) > myLowerLimit then
set myStartASCII to my myGetASCIIValue(character 1 of myWord)
set myEndASCII to my myGetASCIIValue(character -1 of myWord)
if myStartASCII is greater than 64 and myEndASCII is less than 91 then
set myString to contents of myWord
set myString to my myMakeLowercase(myString)
set contents of myWord to myString
set applied character style of myWord to myCharacterStyle
end if
end if
end repeat
end repeat
end tell
end repeat
end tell
activate
display dialog "Done!"
end tell

on myGetASCIIValue(myCharacter)
return ASCII number (myCharacter)
end myGetASCIIValue

on myMakeLowercase(myString)
set myNewString to ""
repeat with myCharacter in characters of myString
if (ASCII number of myCharacter) is greater than 64 and (ASCII number of myCharacter) is less than 91 then
set myNewString to myNewString & (ASCII character ((ASCII number of myCharacter) + 32))
else
set myNewString to myNewString & myCharacter
end if
end repeat
return myNewString
end myMakeLowercase


Thanks,

Ole

Olav Kvern

unread,
Mar 11, 2003, 5:27:37 PM3/11/03
to
Gang--

Here's another approach--you can change the variable "myChangeAll" to false to limit your search to the story containing the selected text frame (or set it to true to search all stories). At some point, I should probably revise it to use Shane's method of case detection/conversion--but that's not really the slowest part (it's the iteration that's slow).

--ChangeAllCapsToSmallCaps.scpt
--An InDesign 2.0 script
--Changes all of the text that has been typed as ALL CAPS
--(i.e., not formatted using the All Caps case option)
--to the Small Caps case option.
--

--The variable "myChangeAll" determines the scope of the change. If the value is set to
--True, all stories in the document will be changed; if it's set to False, only the parent story
--of the first text frame in the selection will be changed.
set myChangeAll to false

--The variable "myLowerLimit" sets the minimum word length--if the
--word is shorter than the value of this variable, it will be ignored.
set myLowerLimit to 2
tell application "InDesign 2.0.2"
tell active document
--Create the "SmallCaps" character style if it does not already exist.
try
set myCharacterStyle to character style "SmallCaps"
on error
set myCharacterStyle to make character style with properties {name:"SmallCaps", tracking:50, capitalization:small caps}
end try

if myChangeAll is true then

repeat with myStoryCounter from 1 to (count stories)
set myStory to object reference of story myStoryCounter

my myChangeStory(myStory, myLowerLimit, myCharacterStyle)
end repeat
else
set mySelection to selection
if (count mySelection) > 0 then
if class of item 1 of mySelection is text frame then
set myTextFrame to item 1 of mySelection
set myStory to object reference of parent story of myTextFrame
my myChangeStory(myStory, myLowerLimit, myCharacterStyle)
end if
end if
end if

end tell
activate
display dialog "Done!"
end tell

on myChangeStory(myStory, myLowerLimit, myCharacterStyle)
tell application "InDesign 2.0.2"

tell myStory
repeat with myParagraphCounter from 1 to (count paragraphs)
set myParagraph to object reference of paragraph myParagraphCounter of myStory
repeat with myWordCounter from 1 to (count words of myParagraph)
set myWord to object reference of word myWordCounter of myParagraph
if (count characters of myWord) > myLowerLimit then
set myStartASCII to my myGetASCIIValue(character 1 of myWord)
set myEndASCII to my myGetASCIIValue(character -1 of myWord)
if myStartASCII is greater than 64 and myEndASCII is less than 91 then
set myString to contents of myWord
set myString to my myMakeLowercase(myString)
set contents of myWord to myString
set applied character style of myWord to myCharacterStyle
end if
end if
end repeat
end repeat
end tell

end tell
end myChangeStory

Shane Stanley

unread,
Mar 11, 2003, 5:23:29 PM3/11/03
to
in article 1de83...@WebX.la2eafNXanI, Olav Kvern wrote:

> Here's the script I sent to Wilma (Jay's right--it *is* slow):

This should speed it up a bit by skipping the (slow) calls to the "ASCII
number" and "ASCII character" commands.

set myLowerLimit to 2
tell application "InDesign 2.0.2"
tell active document
--Create the "SmallCaps" character style if it does not already exist.
try
set myCharacterStyle to character style "SmallCaps"
on error
set myCharacterStyle to make character style with properties
{name:"SmallCaps", tracking:50, capitalization:small caps}
end try
repeat with myStoryCounter from 1 to (count stories)

tell story myStoryCounter
repeat with myWordCounter from 1 to (count words)
set myWord to word myWordCounter
if (length of myWord) > myLowerLimit and myWord does not contain "<"
then
set myStart to character 1 of myWord
set myEnd to character -1 of myWord
if myEnd is less than "[" and myStart is greater than "@" then
set myWord to my myMakeLowercase(myWord)
set properties of word myWordCounter to {contents:myWord, applied
character style:myCharacterStyle}


end if
end if
end repeat

end tell
end repeat
end tell
activate
display dialog "Done!"
end tell


on myMakeLowercase(myString)
set lc to "abcdefghijklmnopqrstuvwxyz"
set uc to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
set oldDelims to AppleScript's text item delimiters
repeat with i from 1 to 26
set AppleScript's text item delimiters to {item i of uc}
set myString to text items of myString
set AppleScript's text item delimiters to {item i of lc}
set myString to myString as text
end repeat
set AppleScript's text item delimiters to oldDelims
return myString
end myMakeLowercase

--
Shane Stanley, ssta...@myriad-com.com.au

Shane Stanley

unread,
Mar 11, 2003, 9:07:32 PM3/11/03
to
in article 1de83...@WebX.la2eafNXanI, Olav Kvern wrote:

> it's the iteration that's slow

How about confining the search to capitalised words only, via something
like:

set cappedWords to object reference of every word of every story whose
contents is less than "["

--
Shane Stanley, ssta...@myriad-com.com.au

Olav Kvern

unread,
Mar 12, 2003, 4:38:38 PM3/12/03
to
Shane--

Your proposed filter clause won't work. I wish it would. In fact, I've tried just about every filter clause I can think of to narrow the search and avoid iterating through every word of every story. No luck so far.

I've also been looking for a Mac OS regular expression scripting extension, but the only one I've found (from Leonard Rosenthal) doesn't want to work on my OS X Powerbook. I may have more luck with some sort of Unix shell script.

Thanks,

Ole

Shane Stanley

unread,
Mar 12, 2003, 5:19:36 PM3/12/03
to
in article 1de83...@WebX.la2eafNXanI, Olav Kvern wrote:

> Your proposed filter clause won't work. I wish it would. In fact, I've tried
> just about every filter clause I can think of to narrow the search and avoid
> iterating through every word of every story. No luck so far.

Hmmm.... it worked on a simple document here, but simple might be the key.


>
> I've also been looking for a Mac OS regular expression scripting extension,
> but the only one I've found (from Leonard Rosenthal) doesn't want to work on
> my OS X Powerbook. I may have more luck with some sort of Unix shell script.

I believe the Satimage scripting addition supports RE and also runs under OS
X. You should be able to track it down via macscripter.net.

--
Shane Stanley, ssta...@myriad-com.com.au

Olav Kvern

unread,
Mar 12, 2003, 5:20:11 PM3/12/03
to
Gang--

Here's yet another version that clears up a logic problem that I'd introduced in the If statement that decides whether a word is typed in all caps. It might even be a bit quicker.

Thanks,

Ole

--ChangeAllCapsToSmallCaps.scpt
--An InDesign 2.0 script
--Changes all of the text that has been typed as ALL CAPS
--(i.e., not formatted using the All Caps case option)
--to the Small Caps case option.
--
--The variable "myChangeAll" determines the scope of the change. If the value is set to
--True, all stories in the document will be changed; if it's set to False, only the parent story
--of the first text frame in the selection will be changed.
set myChangeAll to false
--The variable "myLowerLimit" sets the minimum word length--if the
--word is shorter than the value of this variable, it will be ignored.

set myLowerLimit to 1

tell application "InDesign 2.0.2"
tell active document
--Create the "SmallCaps" character style if it does not already exist.
try
set myCharacterStyle to character style "SmallCaps"
on error
set myCharacterStyle to make character style with properties {name:"SmallCaps", tracking:50, capitalization:small caps}
end try

if myChangeAll is true then

repeat with myStoryCounter from 1 to (count stories)

set myStory to object reference of story myStoryCounter
my myChangeStory(myStory, myLowerLimit, myCharacterStyle)
end repeat
else
set mySelection to selection
if (count mySelection) > 0 then
if class of item 1 of mySelection is text frame then
set myTextFrame to item 1 of mySelection
set myStory to object reference of parent story of myTextFrame
my myChangeStory(myStory, myLowerLimit, myCharacterStyle)

end if
end if
end if

end tell
activate
display dialog "Done!"
end tell

on myChangeStory(myStory, myLowerLimit, myCharacterStyle)
tell application "InDesign 2.0.2"

tell myStory
repeat with myParagraphCounter from 1 to (count paragraphs)
set myParagraph to object reference of paragraph myParagraphCounter of myStory
repeat with myWordCounter from 1 to (count words of myParagraph)
set myWord to object reference of word myWordCounter of myParagraph

if (count characters of myWord) > myLowerLimit then

set myStart to character 1 of myWord
set myEnd to character -1 of myWord

if ((ASCII number (myStart)) is greater than 64 and (ASCII number (myStart)) is less than 91) and ((ASCII number (myEnd)) is greater than 64 and (ASCII number (myEnd)) is less than 91) then

set myString to contents of myWord
set myString to my myMakeLowercase(myString)

set properties of myWord to {contents:myString, applied character style:myCharacterStyle}

end if
end if
end repeat

end repeat
end tell
end tell
end myChangeStory

on myMakeLowercase(myString)

Sandee Cohen

unread,
Mar 12, 2003, 5:38:18 PM3/12/03
to
Guys,

I know I shouldn't even be following this thread (given my total ignorance of scripting), but would this help make the script run faster.

Just as you set a LowerLimit to skip single letter words such as I or A, why not set an UpperLimit to skip words over a certain length.

Most acronyms are under 7 or 8 letters. So skipping all words over 9 letters might reduce the number of words looked at.

Olav Kvern

unread,
Mar 12, 2003, 6:46:36 PM3/12/03
to
Sandee--

It's not a bad suggestion--but it probably wouldn't help that much. What makes it slow is that we have to look at every word. Ideally, we'd have some way of narrowing the number of words that we have to examine in the first place, but we haven't figured out a way to do that yet.

Thanks,

Ole

Shane Stanley

unread,
Mar 12, 2003, 8:10:38 PM3/12/03
to
Ole,

Have you tried:

set cappedWords to object reference of every word of every story whose

contents < ("[" as Unicode text)

Then you could get all the words in one event, and do the checking there.

--
Shane Stanley, ssta...@myriad-com.com.au

Olav Kvern

unread,
Mar 13, 2003, 2:51:37 PM3/13/03
to
Gang--

Okay. I think this is about done, thanks to Shane's mastery of AppleScript filter clauses. This one is much faster, and I added a couple more features.

--ChangeAllCapsToSmallCaps.scpt
--An InDesign 2.0 script
--Changes all of the text that has been typed as ALL CAPS
--(i.e., not formatted using the All Caps case option)
--to the Small Caps case option.
--
--The variable "myChangeAll" determines the scope of the change. If the value is set to
--True, all stories in the document will be changed; if it's set to False, only the parent story
--of the first text frame in the selection will be changed.
set myChangeAll to false
--The variable "myLowerLimit" sets the minimum word length--if the
--word is shorter than the value of this variable, it will be ignored.
set myLowerLimit to 1
tell application "InDesign 2.0.2"

set myTextObjects to {insertion point, character, word, line, text, paragraph, text style range, text column, story}

tell active document
--Create the "SmallCaps" character style if it does not already exist.
try
set myCharacterStyle to character style "SmallCaps"
on error
set myCharacterStyle to make character style with properties {name:"SmallCaps", tracking:50, capitalization:small caps}
end try
if myChangeAll is true then

set myFoundItems to object reference of every word of every story whose contents < ("[" as Unicode text)
my myChangeText(myFoundItems, myLowerLimit, myCharacterStyle)

else
set mySelection to selection
if (count mySelection) > 0 then
if class of item 1 of mySelection is text frame then
set myTextFrame to item 1 of mySelection
set myStory to object reference of parent story of myTextFrame

set myFoundItems to object reference of every word of myStory whose contents < ("[" as Unicode text)
my myChangeText(myFoundItems, myLowerLimit, myCharacterStyle)
else if class of item 1 of mySelection is in myTextObjects then
set myTextFrame to parent text frame of item 1 of mySelection

set myStory to object reference of parent story of myTextFrame

set myFoundItems to object reference of every word of myStory whose contents < ("[" as Unicode text)
my myChangeText(myFoundItems, myLowerLimit, myCharacterStyle)

end if
end if
end if
end tell
activate
display dialog "Done!"
end tell

on myChangeText(myFoundItems, myLowerLimit, myCharacterStyle)
tell application "InDesign 2.0.2"
repeat with myWordCounter from (count myFoundItems) to 1 by -1
set myWord to object reference of item myWordCounter of myFoundItems
if contents of myWord = "Kvern" or contents of myWord = "And" then
set myText to contents of myWord
end if

if (count characters of myWord) > myLowerLimit then
set myStart to character 1 of myWord
set myEnd to character -1 of myWord
if ((ASCII number (myStart)) is greater than 64 and (ASCII number (myStart)) is less than 91) and ((ASCII number (myEnd)) is greater than 64 and (ASCII number (myEnd)) is less than 91) then
set myString to contents of myWord
set myString to my myMakeLowercase(myString)
set properties of myWord to {contents:myString, applied character style:myCharacterStyle}
end if
end if
end repeat

end tell
end myChangeText

on myMakeLowercase(myString)
set myNewString to ""
repeat with myCharacter in characters of myString
if (ASCII number of myCharacter) is greater than 64 and (ASCII number of myCharacter) is less than 91 then
set myNewString to myNewString & (ASCII character ((ASCII number of myCharacter) + 32))
else
set myNewString to myNewString & myCharacter
end if
end repeat
return myNewString
end myMakeLowercase


For whatever reason, the "as Unicode text" approach doesn't work for the logical test inside the myChangeText handler, so I've retained the original ASCII number version.

Thanks,

Ole

Olav Kvern

unread,
Mar 13, 2003, 3:30:01 PM3/13/03
to
DavidT--

LOL! FWIW, IMHO, they're a FOL.

SWAK,

Ole

DavidT

unread,
Mar 13, 2003, 3:10:10 PM3/13/03
to
ACRONYM

all caps ruin or 'nerd' your material

Gee, that's helpful, ain't it?

Mike Witherell

unread,
Mar 14, 2003, 11:44:19 AM3/14/03
to
Ole,

Does this script for initialisms exist also in VBscript? I have alot of Federal users who can only work from PCs. groan. Those poor souls.

Mike Witherell in Washington D.C.

Scott McCullough

unread,
Mar 14, 2003, 1:13:29 PM3/14/03
to
For those who'd rather not delve into scripting, it should be easy to configure Gregg Swann's Torquemada the Inquisitor to perform this operation on a tagged text file extracted from ID. I used to use it extensively a few years ago, and I rarely found anything it couldn't be programmed to modify. It's been awhile since I last used it, so I can't remember all the wildcard and wildstring functions, but it's a powerful and easy-to-use GREP tool written specifically for DTP work. Just an alternative path you may wish to investigate...

Scott

Olav Kvern

unread,
Mar 14, 2003, 3:02:47 PM3/14/03
to
Scott--

It's not a bad idea--but the trouble is that tagged text will not always give you a clean "round-trip" from InDesign due to bugs in the import filter and/or oversights in the filter's design.

There's no need for anyone to "delve into" scripting--the end product of this thread should be a working script that anyone can use. No scripting knowledge necessary.

Wilma has had some problems with the last version of the script, so I expect I'll have to post at least one more before I consider it "final" and post it at adobe studio exchange.

Mike--

I'll write a VBScript version as soon as I can.

Thanks,

Ole

Scott McCullough

unread,
Mar 14, 2003, 3:40:45 PM3/14/03
to

>It's not a bad idea--but the trouble is that tagged text will not always
give you a clean "round-trip" from InDesign due to bugs in the import
filter and/or oversights in the filter's design.


Ole:

Hmmm, I wasn't aware of that. I used to work in a textbook comp shop where we used XPress Tags extensively, which is how I became acquainted with Torquemada. It was absurdly easy to export a story, make some quick meta-changes (either with Torquemada or just in BBEdit), and flow it back in. To make the same changes manually would have taken hours, with a high risk of errors. Way cool stuff once I established the right workflow.

I've not worked with ID's tags except for a few hours of tinkering one slow day. My main impression was that ID tags were mind-blowingly verbose compared to XPress Tags, though that may have been an incorrect impression.

Just out of curiousity, what are the bugs in ID's filter? Do you think they'll be sorted out when ID3 is released? I can't imagine a large composition shop considering ID until the tagging language was at least as functional as XPress Tags.

Scott

Olav Kvern

unread,
Mar 14, 2003, 3:57:05 PM3/14/03
to
Scott--

Multiple master fonts will almost never make the round trip. They're dead, I know, but they still get used. Inline graphics and inline text frames are also not exported.

If your documents don't use either of the above, there's a good chance you'll be able to round trip tagged text (the only way to be certain is to try it).

LateNight software has released TagOn, an XPressTags import/export filter. You might want to take a look at it at <http://www.latenightsw.com>.

I can't comment on future releases.

Thanks,

Ole

Shane Stanley

unread,
Mar 14, 2003, 5:04:13 PM3/14/03
to
in article 1de83...@WebX.la2eafNXanI, Scott McCullough wrote:

> It was absurdly easy to export a story, make some quick meta-changes (either
> with Torquemada or just in BBEdit), and flow it back in.

But absurdly tedious to do it when there were dozens of stories. Yes, it's a
great method, but again something that can be further automated via
scripting.

--
Shane Stanley, ssta...@myriad-com.com.au

Olav Kvern

unread,
Mar 14, 2003, 5:10:28 PM3/14/03
to
Scott, Shane--

If we're going to include external utilities and/or scripting extensions, there are a number of things that could make this easier. Prefab's Text Machine also comes to mind. But I think we can come up with a reasonable script without having to rely on any external help.

It's my usual "Desert Island" kind of thinking. Suppose you have nothing but a stone knife and a ball of twine....<g>

Thanks,

Ole

0 new messages