[JS] [CS3] Apply the character Style to the first word

I'm a noob that Javascript is concerned, and I expected a little guidance.

Here is my scenario: I have a book that was composed in a single file; the main content is in a story. I want to select the first word in each block of text on each page and apply a character style. My goal is to use this character style to indicate the page breaks in the XML document - I maps to a specific tag style.

So far, I have this poor specimen:

myDocument var = app.activeDocument;
myPage var = myDocument.pages.item (1);
var myTextFrame = myPage.textFrames.item (0);


If (app.activeDocument.stories [0] .paragraphs [0] .words [0]! = null)
myTextFrame.paragraphs.item (0).words.item (0) = .appliedCharacterStyle
myDocument.characterStyles.item ('foo');

I know, I did not implement any kind of loop again (which will be more complicated given that there will be some blank backs, etc.). What I try to do in this is to select the first word in the first paragraph on the second page - which it does in reality. It's the first paragraph of the second begins on the first page, so I select that word on the first page, second page.

As I said, a lot of work to do but a bit of help on getting to the right word would be most appreciated.

Well, you were on the right track, but the "myText" test fails if there is no block of text on a page, because it fails a line earlier

> var myTextFrame = myPage.textFrames.item (0);

just before that, you must test the number of blocks of text:

If (myPage.textFrames.length > 0)

{

... your stuff...

}

Use it only if you are absolutely positive that there is just a block of text on each page! A slightly better way would be to always loop on each textframe:

for (frames = 0; frames

{

var myTextFrame = myPage.textFrames.item (frames);

.. etc.
}

in this case you don't have test his first length (the loop will not be executed if there is zero text blocks).

[Grumpy] Since you have only a continuous story, an even better way would be to loop on texts related to this single story executives. You must identify the story somehow, and I usually click on the text cursor in the one that I need:

monarticle = app.selection [0] .parentStory;

or you can rely on the fact that the story begins as part of text on page 1:

monarticle = app.activeDocument.pages [0] .stories [0];

(I think this should work.) Then, each frame of the story until the end can be found in the table

myStory.textContainers

which are usually text blocks. Make a loop on them to help

for (image = 0; frame)

{

myTextFrame = myStory.textContainers [frame];

.. etc.

}

Tags: InDesign

Similar Questions

  • How to apply a character Style that has already been made in a document model?

    First of all, I would like to thank everyone who helps. I am a complete newbie to the script and appreciate your help.

    I mainly use GREP expressions to search for patterns in a document and apply a character Style that has already been done. This character style did not help script, but just in InDesign when the production and implementation of the model.

    var myDoc = app.activeDocument;
    
    
    //Clear the find/change grep preferences.
    app.findGrepPreferences = NothingEnum.nothing;
    app.changeGrepPreferences = NothingEnum.nothing;
    
    //Set the find options.
    app.findChangeGrepOptions.includeFootnotes = false;
    app.findChangeGrepOptions.includeHiddenLayers = false;
    app.findChangeGrepOptions.includeLockedLayersForFind = false;
    app.findChangeGrepOptions.includeLockedStoriesForFind = false;
    app.findChangeGrepOptions.includeMasterPages = false;
    
    //GREP Expression for finding all HEADERS
    app.findGrepPreferences.findWhat = ".+\n";
    
    //Applying formatting changes to put into All Caps, Bold and changing the font size to 12 pt.
    app.changeGrepPreferences.capitalization = Capitalization.allCaps;
    app.changeGrepPreferences.fontStyle = "Bold";
    app.changeGrepPreferences.pointSize = "12";
    myDoc.changeGrep();
    
    //Clear the find/change preferences after the search.
    app.findGrepPreferences = NothingEnum.nothing;
    app.changeGrepPreferences = NothingEnum.nothing;
    

    This is how I currently. I will manually define the changes made to the text. The problem is, each model uses a different set of fonts and not all use them "BOLD", for example Sabon can use THIS "BOLD".

    I would like to know how to apply a character Style and tried to look, but nothing seems to work.

    Any help would be appreciated.

    Thank you.

    app.changeGrepPreferences.appliedCharacterStyle = "A";

  • How to apply a character style to url an email?

    Mac-Indesign CC

    I am trying too use a grep style to apply a character style to url an email?

    Is this possible?

    Better to consider Nina Storm

    Hello

    Try this:

    [^\s]+@[^\s]+

  • "BOLD" from the first words of each line?

    I wonder if there is a way to fully automate this. I'm style expandable body of interview-format the text, and I would only the first word of each paragraph, be bold if they are one of the three names. I currently have a nested style black the first word of each paragraph, but not all of the paragraphs in the text begin with a name of interview. Can anyone help?

    Depends on if you need it to happen automatically when you start new documents with interviews, or if you need to do just for a single doc where all your text has already been sent to. If the latter, I had:

    (1) make a duplicate of the nested-style-parastyle called BoldNames

    (2) remove the nested style old style paragraph - now zero paragraphs have the nested style applied, and you have a separate unused paragraph with the nested style in style.

    (3) research the doc with a GREP query:

    To find

    ^(Jake|) Joel | James)

    Implement

    $

    with the format of

    BoldNames

    In this way, only the paragraphs that have one of these names at the beginning of the paragraph will be marked with the paragraph style that owns the nested style that applies "BOLD".

  • How can I make Pages capitalize the first word in a sentence?

    How can I make Pages capitalize the first word in a sentence? The I phone t - it, the iPad does, why not not iMac using Pages capitalize the first word on a new sentence?

    Pages of IOS and IOS itself remain different implementations of Pages v5.6.1 for Mac and OS X. In any version of Pages v5, if there was an option to preferences in Pages ' 09, there is no auto-capitalisation function.

    See my previous post is launching an OS X App Store free application, which can be applied to auto-capitalisation to your Pages v5 documents.

  • GREP in parastyle - all the words in tiny paragraph outside the first word

    Hello. I hope for more assistance with the implementation of a GREP in a paragraph style.

    I'm composition several books and the many subtitles (all in the same paragraph style) are written so that each word is capitalized. The editor here now only the first word of each subheading to be capitalized, and instead of working my way through them manually, I was wondering if a GREP could achieve this? I know there are exceptions with proper names, but they are few.

    Any help appreciated, as any quick explanation on each part of the GREP so I understand better how it works!

    If the text was actually indexed using corks, it cannot be changed using GREP, but it may be film script. Script updated Dave Saunders style find/change case script would probably do what you want (change because of the sentence).

  • Why no iphone 6 and iPad (mini and Air2) capital at the beginning of the first word in the search bar of Safari

    Why no iPhone 6 and iPad (Mini and Air 2) not capitalize first letter of the first word in Safari on the search bar?

    Web addresses contain no capital letters, nor do email. If looking at you any new credit card and it says to activate this card go to www.CardnameService.com/Activate, their meaning is www.cardnameservice.com/activate. It's the same thing.

    The above examples are that of the examples.

  • Receive emails from retailers who have 'click' as the first word.

    Original title: cannot find ' click on ' addresses?

    Lately I have received emails from retailers who have 'click' as the first word, such as click.elowes.com and I always get a 'not found '.  What is the problem?

    Hello

    As you use Windows Live mail, you can also post your request in the Windows Live forums to get help.

  • How to reference the first word in a text frame (threaded)?

    Hello.

    I have a series of threaded text images.
    I want to be able to reference the first word of each of them.
    [This is no big deal to start the project and do it all on the fly].

    Any ideas how I can get there?

    Any help would be appreciated.

    To get the content of the Word use myWord. content to move the Word use myWord. move (LocationOptions.AT_BEGINNING, myDestinationTextFrame);

  • What is the best way to change the color of the first word in a paragraph?

    I have a lot of paragraphs where I want that the first word to keep the same font, the size, the type - but I want to change just the color of the lettering.

    I suggest to do this:

    (1) change your BC 4567000000 to the following line:

    4,567,000,000 BC - name derived from Hades.

    (2) add the following line after the top of the page:

    . first-word {color: red ;}}

    Note the period in the above code.

    The top of line will now look like this:

    H1 {make-size: 200%; do-family: "Comic Sans MS"; color: #66FFFF; text-align: center ;}}

    H2 {make-size: 100%; do-family: "Comic Sans MS"; color: Red ;}}

    p {make-size: 100%; do-family: "Comic Sans MS"; color: #EEEEEE ;}}

    . First-word {color: red ;}}

    Alternatives are almost similar to this one but try this one and then come back and demand the implementation of alternatives.

  • Capturing the first word of a textbox

    Good, small problem, I can not understand how to get the first word in a text box. Here's the code that captures the full range:

    var LSTN = "LSTN" + xfa.form.OUTSTCHK12.FormPage1.Subform1.PayeeLastName.rawValue; ".

    If someone could help me please, I would be very grateful.

    Well, now you know ho to spread the word, it is just a case of assigning to another field. Assuming that the other field is called OtherField, you would use a command like this:

    OtherField.rawValue = words [0]

    Paul

  • Capitalize the first word in a sentence

    Hi I was looking for a method/function to capitalize only the first word of a string. (not every word in the string according to the capfirst does very well)

    Thank you

    Oli

    Thank you very much, just work, maye, I would have thought that, no rocket science, doh!

  • Taking the first word only

    Hello, I got a single column, I just want to take only the first word of this column

    Column of blabla
    Hello how are there you?

    Please tel me how I can take only first Hello there and if I want to take the second word in the first place that should I do thank you
    SQL> with t as
    (
     select 'Hello how are you' str from dual union all
     select 'God bless you' str from dual union all
     select 'Take care my love' str from dual
    )
    ---
    ---
    select str, regexp_substr(str,'\w+') str1, regexp_substr(str,'\w+ +\w+') str2 from t
    /
    STR               STR1              STR2
    ----------------- ----------------- -----------------
    Hello how are you Hello             Hello how
    God bless you     God               God bless
    Take care my love Take              Take care        
    
    3 rows selected.
    
  • I'm looking for links Hypertext in find/replace the dialogue (without applying a character style).

    I have 7000 hyperlinks in my document, with different character styles ("italic", "bold" and "italic +"BOLD""). I need to apply the blue color to each of them. If I ask a new character style "hyperlink" to all, I'll lose my formatting.

    Is there a way to find hyperlinks (for themselves, not their format) dialog find/replace in order to create and apply 4 different character styles ('hyperlink_regular', 'hyperlink_bold', 'hyperlink_italic' and ' hyperlink_bold + italic")?

    Sorry for my English, thanks for the help!

    Use Javascript!

    You can use this Javascript, for example. (Instructions on how to use a JavaScript in InDesign can be found elsewhere).

    blue = app.activeDocument.swatches.item("Blue");
    for (a=0; a
    

    Take care to provide the correct color swatch name in the first line.

  • InDesign CS3 - apply the style to the selection no longer works!

    Hello

    I have a little problem with InDesign CS3 and caraters style and paragraph style.

    style options in the options section and in the text, and in a style of object (even in GENERAL pannel), 'style to apply to the selection' appear in gray and I can not select, (or check), and is uncheked.

    In the room included an immage of a panel with the uncheched 'apply the style selection '.

    Please help me, what I have to do?

    I have try all thinghs but not reistalling jump is the last chance.

    Thank you for advice.

    ALE

    Your English is very good.

    The first thing I would try replacing the InDesign preferences. It seems to me that if you have repaired permissions of Mac files, but have does not replace the application preferences themselves. On Mac, the fast lane is close ID, then restart and IMMEDIATELY (almost instantly) press and hold the control + Cmd + Opt shift keys while the application starts. You should see a dialog box asking to confirm the replacement of preference. If you don't see the dialog box, you were not fast enough with the keyboard.

    You can also do a manual replacement. Look for the InDesign Defaults and InDesign SavedData files (these are probably hidden, but it will be in your user library) and just rename, move or delete. ID will create a new set at its launch. This has the advantage that you can recover your customizations by moving the prefs old return in the case where replacing them does not solve your problem.

    Things you lose are non-standard styles default and shades, which can be re-imported from a document that uses and document presets and a printer that can be saved from the dialog boxes "Set" before replacing your prefs and reloaded after same dialog boxes.

    Peter

    Edit: I see while I was busy typing Eugene was busy looking at the picture more closely I have and gave the real answer. Good info on the replacement of prefs, however, if you need it in the future.

Maybe you are looking for