Script to apply a style to currently selected text

I can only find example scripts that work on complete files. What I want, is a script that works on currently selected text.
If I can create a macro that applies a specific paragraph style to all currently selected paragraphs, or a character style to currently selected text, I can put that style under a shortcut key.
That way, "emphasis" or "strong" can be put under ctrl-b, for example.
If there is another way to achieve the same (in RH 9), I would be interested to hear it as well.
Kind regards,
Erwin Timmerman

I had a quick look at Macro Express, but it seems that it only records key strokes and mouse clicks etc. This means that it only works if I have the style pod constantly open (which I do), always in the exact same position, with the same filter styles selected, and with the same CSS loaded, positioned at the same location in the scroll bar.
Am I correct in assuming this, or is there a better way to program it?
I am not sure this would be possible all the time. What's more, this script should work across multiple computers with different layouts, and with writers who don't really want to hack to get it working.
With character styles there would be the possibility to automatically switch to HTML view, cut, write <span...>, paste, write </span>, go back to design view.
But paragraph styles? That would be harder to do in HTML view, especially for multiple selected lines.

Similar Messages

  • Applying a style only to selected text

    In the latest version of Pages is there anyway to apply a style only to selected text and not to whole paragraph? Thanks.

    Yes, use Character Styles.
    Peter

  • How to write script to apply character style?

    Hi,
    I'm on a Macbook pro and without a number pad so I can't assign a shortcut for the character styles. I did hear of a roundabout solution where you can assign a shortcut to a script which applies the character styles. Can anyone write this script?
    My character style is called 'Features bold'.
    I'm new to scripting, sorry if this is a dumb question.
    Cheers

    Hi,
    1. Save this code as .jsx file inside your Script Panel folder
    2. Apply a shortcut using Edit:Keyboard shortcuts... menu
    Option to choose:
    suggest to choose an option "context": "Text", so you can use more shortcuts which are busy with other contexts.
    #target indesign
    if (app.selection && app.selection[0].hasOwnProperty ("baselineShift") ) {
      var cName = "Features bold";
      var mCstyle = app.activeDocument.characterStyles.item(cName);
      if (mCstyle.isValid)
           app.selection[0].applyCharacterStyle(mCstyle);
      else
           alert ("CharStyle: " + cName + " not found");
    else
      alert ("Some text supposed to be selected...");
    Jarek

  • A script to apply cell style to entire rows containing a specific text

    Hi,
    I am using InDesign CC 2014
    Does anyone know how to apply a cellstyle based on text contents found in a cell in javascript?
    I need to search the document and change cell style in entire row to "cellStyle01" if the text "someText" appear in cell.
    I've found similar script here in forum which apply table style, but don't know how to change it to apply cell style!
    var curDoc = app.activeDocument;
    var allTables = curDoc.stories.everyItem().tables.everyItem();
    app.findTextPreferences = app.changeTextPreferences = null;
    app.findTextPreferences.findWhat = "someText";
    var allFounds = allTables.findText();
    app.findTextPreferences = app.changeTextPreferences = null;
    for ( var i = 0; i < allFounds.length; i++ ) {
    var curFound = allFounds[i];
    if ( curFound.length == 1 ) {
    var curFoundParent = curFound[0].parent; 
    // curFoundParent.parent.appliedTableStyle = curDoc.tableStyles.itemByName( "tableStyle" ); 
    curFoundParent.parent.appliedCellStyle = curDoc.cellStyles.itemByName("cellStyle01"); 
    Thanks!

    Hi,
    Try this,
    var doc = app.activeDocument, 
        _tables = doc.stories.everyItem().textStyleRanges.everyItem().getElements(), 
        i, j, k, l, a, _rows,_cells, rowlen; 
    for(i =0;i<_tables.length;i++) 
        for(j =0;j<_tables[i].tables.length;j++) 
            _rows = _tables[i].tables[j].rows; 
            for(k =0;k<_rows.length;k++) 
                _cells = _rows[k].cells; 
                for(l =0;l<_cells.length;l++) 
                    if(_cells[l].contents == "someText") 
                        rowlen = _cells[l].parent.cells.length; 
                        while(rowlen--) 
                              _cells[rowlen].appliedCellStyle = doc.cellStyles.item("cellStyle01"); 
    Regards,
    Chinna

  • Script for applying object style to only tif, or eps or...(by extension)

    We need to apply object style to only eps files in doc, or tif.... How to do this? Maybe someone have a script?
    thanks

    @kajzica – I don't have a script for that, but it is scriptable. You surely mean that you want to apply the object styles to the container frame of the images, aren't you?
    A few minutes later – try the following ExtendScript (JavaScript) code:
    You could edit the names of the two object styles at the beginning of the script code.
    OR: you could first run the script, the script will add two object styles to the document that you can edit afterwards.
    The script will sort the EPS and the TIFs from the other image types.
    Make sure that all graphics are up-to-date and linked correctly!!
    //ApplyObjectStylesTo_ContainersOf_TIF_EPS.jsx
    //Uwe Laubender
    * @@@BUILDINFO@@@ ApplyObjectStylesTo_ContainersOf_TIF_EPS.jsx !Version! Thu Dec 12 2013 13:15:30 GMT+0100
    //Edit your style names here. Change the name between the two " " only!!
    //OR: edit your object styles in InDesign after running the script.
    var styleNameForEPS = "EPS-Containers-Only";
    var styleNameForTIF = "TIF-Containers-Only";
    app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
    app.doScript(_ApplyObjectStylesToContainers, ScriptLanguage.JAVASCRIPT, [], UndoModes.ENTIRE_SCRIPT, "Apply object styles to containers for TIF and EPS graphics");
    function _ApplyObjectStylesToContainers(){
    var d=app.documents[0];
    var allGraphicsArray = d.allGraphics;
    if(!d.objectStyles.itemByName(styleNameForEPS).isValid){
        d.objectStyles.add({name:styleNameForEPS});
    if(!d.objectStyles.itemByName(styleNameForTIF).isValid){
        d.objectStyles.add({name:styleNameForTIF});
    for(var n=0;n<allGraphicsArray.length;n++){
        //The EPS case:
        if(allGraphicsArray[n].getElements()[0].constructor.name === "EPS"){
            allGraphicsArray[n].parent.appliedObjectStyle = d.objectStyles.itemByName(styleNameForEPS);
        //The TIF case
        if(allGraphicsArray[n].getElements()[0].constructor.name === "Image" && allGraphicsArray[n].getElements()[0].imageTypeName === "TIFF"){
            allGraphicsArray[n].parent.appliedObjectStyle = d.objectStyles.itemByName(styleNameForTIF);
    }; //END: function _ApplyObjectStylesToContainers()
    Uwe

  • Script to apply cell style after search for paragraph

    Hello,
    can somebody help my do a script to search for all occurences of a paragraph format in tables and then apply a cell style to the enclosing cell for a document.
    Thanks in advance.
    Peter
    BTW Mac InDesign CS 6

    Hi,
    use this:
    var mDoc = app.activeDocument,
    pST = mDoc.paragraphStyles.item("paraStyleName"),
    cST = mDoc.cellStyles.item("cellStyleName"),
    mFound, mParent, count;
    app.findTextPreferences = null;
    app.findTextPreferences.appliedParagraphStyle = pST;
    mFound = mDoc.findText();
    count = mFound.length;
    while (count--) {
         mParent = mFound[count].parent;
         if (mParent.constructor.name == "Cell")
              mParent.appliedCellStyle = cST;
    app.findTextPreferences = null;
    edit paraStyleName and cellStyleName
    Jarek

  • How do I apply a style to the rich text editor in 10.1.2

    I am trying to add text items to a portlet. How do I maintain the style for item text?

    that implies to constrain the styles in the RTE (instead proposing too much choices : font, size etc..)
    A method:
    customize the RTE by reducing the styles to a choice between standard HTML styles (header 1, header 2, body text, paragraph,..).
    Then map these styles to the css styles propsed by Portal.
    As a sample, get all the css from your portal by typing:
    http://<you.machine>/pls/portal/PORTAL.wwv_setting.render_css?p_lang_type=NOBIDI&p_subscriberid=1&p_styleid=12&p_siteid=0&p_rctx=P
    for RTE customizing: http://www.oracle.com/technology/products/ias/portal/pdf/cm_rte_10gr2_features.pdf
    Patrick.

  • Apply Nested Styles Script not working for me anymore

    //DESCRIPTION: Applies nested styles as directly applied character styles.         WARNING: This script will override any character styles which are directly applied to the text with the nested styles applied, and formatting might change!
    (function(){
         function IsValid (obj){
              var err;
              try{
                   if(!obj){return false}
                   if(kAppVersion>=6){
                        return obj.isValid;
                   var test = obj.parent;
                   return true;
              catch(err){return false;}
         function ResetFindPrefs(){
              if(kAppVersion<5){app.findPreferences = null;}
              else{app.findTextPreferences = null;ResetFindChangeOptions();}
         function ResetFindChangeOptions(){
              app.findChangeTextOptions.properties = {
                   includeLockedStoriesForFind:false,
                   includeLockedLayersForFind:false,
                   includeHiddenLayers:false,
                   includeMasterPages:false,
                   includeFootnotes:false,
                   wholeWord:false,
                   caseSensitive:false
         function GetTempColor(doc){
              for(var i=0;i<doc.swatches.length;i++){
                   if(doc.swatches[i].label == 'harbsTempColor'){return doc.swatches[i]}
              return doc.colors.add({label:'harbsTempColor'});
         function GetAppColor(colorName){
              for(var i=0;i<app.swatches.length;i++){
                   if(app.swatches[i].name==colorName){return app.swatches[i]}
              return null;
         if(app.documents.length==0){return}
         kAppVersion = parseFloat(app.version);
         var doc = app.documents[0];
         if(kAppVersion<5){
              var charStyles = doc.characterStyles;
         }else{
              var charStyles = doc.allCharacterStyles;
         var tempDocColor = GetTempColor(doc);
         var colorName = tempDocColor.name;
         var tempAppColor = GetAppColor(colorName);
         var removeAppColor=false;
         if(!tempAppColor){
              removeAppColor=true;
              tempAppColor=app.colors.add({name:colorName})
         for(var i=1;i<charStyles.length;i++){
              var savedColor = charStyles[i].underlineGapColor;
              var finds=undefined;
              var findsLength=0;
              do{
                   if(finds){findsLength=finds.length}
                   charStyles[i].underlineGapColor=tempDocColor;
                   ResetFindPrefs();
                   if(kAppVersion<5){
                        app.findPreferences.underlineGapColor = tempDocColor;
                        app.changePreferences.appliedCharacterStyle = charStyles[i];
                        doc.search("",false,false,'');
                        break;
                   }else{
                        if(kAppVersion<6){
                             app.findTextPreferences.underlineGapColor = tempAppColor;
                        }else{
                             app.findTextPreferences.underlineGapColor = tempDocColor;
                        app.changeTextPreferences.appliedCharacterStyle = charStyles[i];
                        finds = doc.changeText();
                        //alert(finds.length);
              }while(findsLength!=finds.length);
              charStyles[i].underlineGapColor=savedColor;
         tempDocColor.remove();
         if(removeAppColor){tempAppColor.remove()}
    This was a script to apply nested styles directly to the text as character styles.It was supplied to me by someone on this forum to help make a file adaptable to an epub doc. It has worked fine for many months but now it does not. I am wondering if the cause is that I have added two nested styles in the paragraphs, where before there was only one. The paras. are currently set up with nested styles as follows:[none] up to En Space, italic through 5 sentences.                  I am using 5 sentences because I can't figure how to use a para. end as a limiter. I know this is confused but any help will be appreciated. Thanks

    That looks like mine (and someone didn't follow my request on this page) :
    http://in-tools.com/scripts.html
    What doesn't work?
    You can PM me, and I'll try to figure out what's wrong...
    Harbs

  • Is there a script for applying a certain style to several thousands of words arranged in a list?

    Hello, I have tried using FindChangeByList, but I'd pretty much do all the work of pasting every word on the brackets, so i could as well apply the styles by hand.
    So my project involves applying the same style to around 11 thousand words that appear in a book. Those words are mostly names and brands, and they appear throughout the whole text, so applying that style manually would be quite time-consuming.
    I have those words set aside in a list.txt
    Does anyone know if I could use that in any script and apply the style automatically?
    Like I said, pasting every single word into FindChangeByList is out of the question, just like applying the style word by word, it would take forever...
    ...thanks!

    Okay, for anyone that might be interested in this as I was, I found a solution.
    If you want to have a particular text expression on your .txt list to be used as a search parameter by your script, here are a few tips:
    Let's say you want to add the following 2 expressions on your list, without the quotation marks:
    a) "test, test."
    b)"[test] {test}"
    1 - Like Jongware said, you MUST abide by GREP syntax.
    2 - If you want to put an expression on your .txt list that DOES NOT uses characters that represent GREP syntax (example a) with regular text, commas and simple punctuation), you may simply add them to your list between parentheses:
         a) (test, test.)
    3 - If you want the script to search for an expression that DOES CONTAIN characters that are also used by GREP syntax (example b) you can try stuff like:
         b) (\p{Ps}test\p{Pe})
         note the parentheses, because it's a specific text expression
         then note the \p{Ps} and \p{Pe} that mark opening or (s)tarting and closing or (e)nding punctuation such as brackets, braces, parentheses...
    Here is a file with the GREP expressions that helped me solve my problems:
    http://www.kahrel.plus.com/indesign/grep_mapper.pdf
    Although this is a very specific matter and probably easily solvable by all the professional scripters here, I thought I'd share it since it took 3 whole days of studying for me to conclude everything.
    Thanks again, specially to Jongware

  • [JS, CS3] Need help changing tabStop positions of selected text

    Hi all,
    I am writing a script to nudge the tabStop positions of selected text by one point at a time. Sometimes it will be only a tab character selected, and other times it could be several in the paragraph or maybe even the whole story. The problem I am encountering is that when I reference the tabStops as app.selection[0].tabStops it includes ALL the tabStops in the paragraph and NOT just the selected ones. Is there a way to get just the selected tabStops and add a point to their positions? It must be that my referencing is flawed. Thanks for any help.
    Regards,
    Len Swierski

    Hi Len,
    That's not a bad approach, but remember that there may be more tab characters than there are tab stops. I was thinking of getting the location of the selected tab stop relative to the left edge of the text frame (or column, if you're working with multi-column frames) and then comparing it to the location of the tab stop. But I think your approach will work just as well and be quicker.
    Also, remember that when you start moving tab stops around, the index of the tab stop within the tab stops collection can change. If you have tab stop A at 12pt and tab stop B at 16pt, then tab stop A will be item(0) and B will be item (1). But if you move A to 24pt, A will become item(1) and B will be item(0). The index of the tab stop is relative to its location on the tab ruler.
    Thanks,
    Ole

  • No CSS properties apply to the current selection

    I have a style sheet in my root directory. It is showing as being connected to my html page. It is written in with <link href="_css/main.css" rel="stylesheet" type="text/css /">.
    In my Manage Sites section it is shown in  "Advanced Settings" > "Local info" > "Site-wide Media Query file"
    Despite all that when I click on any element in the Design view with either my CSS "Current" or "All" selected it keeps showing the error  "No CSS properties apply to the current selection"
    I have studied other sites of mine line by line where it works and compared it to this one and cannot see anything missing.
    So I really would appreciate being pointed in the right direction.
    Thanks
    keith47

    I don't know as I apply all css manually BUT you have a / after css in the link to the stylesheet you provided below (if its not a typo) which may be causing the issue:
    <link href="_css/main.css" rel="stylesheet" type="text/css /">

  • Apply "Script Labels" to Object Styles?

    Hi again,
    I think I've kind of found a solution to my previous thread. But it involves using Script Labels in order to get it to work. Problem is I've tonnes of text boxes with Object Styles applied that don't have any Script Labels applied to them. Is there a way I can apply a script label to all of my existing text frames that have a particular Object Style already applied to them?
    Thanks in advance.

    You could use essentially the same script I just posted but set the label rather than the itemLayer of each found object. However, it seems like a convoluted approach.
    Dave

  • A filter cannot be applied to the currently selected field. Select a different field

    Hi,
    I am using an InfoPath form to submit the data. In my form I am using one dropdown and one textbox in a repeating table, and the data is fetching from the SharePoint list.
    Scenario: In my SharePoint list there is a column of Company name and other is of Focal Point name. In dropdown contains the company name column.
    I want the functionality that when i select the Company name the associated focal point name should appear in the textbox.
    To achieve this I am using the filter for dropdown but it is showing me error "A filter cannot be applied to the currently selected field. Select a different field."
    Can anyone please tell me how can I do this.
    Thanks in Advanced,

    Hi,
    Please update me any solution for this as I am not able to resolve this.....
    Thanks,

  • Applescript-Apply Character Style to Select Words in InDesign CC

    I'm trying to apply a character style to the first several words of a paragraph. The number of words varies, but it is essentially every word before a comma.
    Here's what I have so far:
    tell application "Adobe InDesign CC 2014"
      tell document 1
      tell page 2
      tell (item 1 of page items whose label is "HabitsContent")
      tell paragraph 2
      repeat with i from 1 to count of characters
      if contents of character i = "," then
      exit repeat
      end if
      end repeat
      set applied character style of characters 1 thru i to "Italic"
      end tell
      end tell
      end tell
      end tell
    end tell
    Viewing the log of the script, it finds the comma; however, the script ends up italicizing the entire paragraph. Any ideas?

    For anyone else who has a similar question, here's what works:
    tell application "Adobe InDesign CC 2014"
    tell paragraph 2 of (item 1 of page items whose label is "HabitsContent") of page 2 of document 1
    set a to paragraph 1 as list
    set a to text item 1 of a
    set old to AppleScript's text item delimiters
    set AppleScript's text item delimiters to {","}
    set font style of characters 1 thru (count of text item 1 of a) to "Italic"
    set AppleScript's text item delimiters to old
    end tell
    end tell

  • JTextPane, Selecting Text and Applying Styles

    Hello,
    Anyone encounter this situation? I have a mini word processor application that I have written using the RTFEditor kit and a JTextPane. To change style, e.g bold, font size, font face, etc, one can select text and then click a button or select a menu item. That part works fine. The styles are primarily changed by using the Action classes provided in the javax.swing.text.* package.
    The problem is, that if a user selected text of more than one style, all of the text is automatically converted to the style of the first part of the text selected, without the user even eanting to change ANY style just yet.
    If anyone knows why this might be happening I would surely appreciate it.
    Thanks,
    acal

    Solution to the style appling problem...
    public void actionPerformed( ActionEvent e )
            if (flag) return;
            if(e.getSource() == boldButton)
                SimpleAttributeSet attrs = new SimpleAttributeSet();
                attrs.addAttribute(StyleConstants.Bold,boldButton.isSelected());
                applyStyleToSelection(attrs);
                editorPane.grabFocus();
                return;
    public void applyStyleToSelection(AttributeSet attrs)
            int start = editorPane.getSelectionStart();
            int end = editorPane.getSelectionEnd();
            DefaultStyledDocument doc = (DefaultStyledDocument) editorPane.getDocument();
            doc.setCharacterAttributes(start, end - start, attrs, false);
            StyledEditorKit styled = (StyledEditorKit) editorPane.getEditorKit();
            MutableAttributeSet mas = styled.getInputAttributes();
            mas.addAttributes(attrs);
        }Filipi Silveira
    [email protected]

Maybe you are looking for

  • The Security Token Service is not available -- SP Server on Windows 7

    I just installed SharePoint Server 2010 on a Windows 7 workstation with the aim of setting up a development environment. Installed all the prerequisites, then SP, everything seemed to go smoothly. However, the Health Analyzer is warning my that "the

  • Embedded Vimeo video not displaying in Safari 5

    I recently embedded a vimeo video into the home page of my iweb website. It displays on most browsers and earlier versions of Safari, but not with Safari 5. Are others running into this problem? Do you have any suggestions? My website is www.tmsnewen

  • Is Contribute part of the Creative Cloud?

    Is Contribute part of the Creative Cloud? I don't see it as a download option.

  • Implications of changing the Planning Calendar

    A Planning Calendar was defined for a Fiscal Calendar periods without 'firming'. The Planning Calendar automatically changed to Calendar Year periods. If we need to reset the Planning Calendar and 'firm' it in a production environment, what are the i

  • E52 unable to see phone numbers

    I am unable to view phone numbers when I browse contacts, I think this is possible as it was in the earlier models of NOKIA E- Series. Any suggestions or help would be appreciated. Thanks in advance. Solved! Go to Solution.