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!
BTW how is the HP printer problem? did you solve it?
BTW how is the HP printer problem? did you solve it?
No, still only ASCII...
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.
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
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
> 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
> 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
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
> 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
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)
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.
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
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
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
LOL! FWIW, IMHO, they're a FOL.
SWAK,
Ole
all caps ruin or 'nerd' your material
Gee, that's helpful, ain't it?
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
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
>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
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
> 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
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