Script for switching master pages

Would it be possible to write a script to do this: Replace one master page with another whenever a certain paragraph style appears? I'm looking for a quick way to replace my A Master (with running header and page number) with the None Master on pages where new chapters begin.
Clark

here you go (it also creates sections)
var ProgressBar = function(/*str*/title){
     var w = new Window('palette', ' '+title, {x:0, y:0, width:340, height:60}),
          pb = w.add('progressbar', {x:20, y:12, width:300, height:12}, 0, 100),
          st = w.add('statictext', {x:10, y:36, width:320, height:20}, '');
     st.justify = 'center';
     w.center();
     this.reset = function(msg,maxValue)
          st.text = msg;
          pb.value = 0;
          pb.maxvalue = maxValue||0;
          pb.visible = !!maxValue;
          w.show();
     this.hit = function() {++pb.value;};
     this.hide = function() {w.hide();};
     this.close = function() {w.close();};
function main(){
var doc = app.documents.item(0);
// Create a list of paragraph styles
var list_of_paragraph_styles = [];
var all_paragraph_styles = [];
var list_of_masters_names=[];
var list_of_masters=[];
for (var i= 0; i<doc.masterSpreads.length;i++){
    list_of_masters_names.push(doc.masterSpreads[i].name);
    list_of_masters.push(doc.masterSpreads[i]);
list_of_masters_names.push("undefined");
doc.paragraphStyles.everyItem().name;
for(var i = 0; i < doc.paragraphStyles.length; i++) {
           list_of_paragraph_styles.push(doc.paragraphStyles[i].name);
           all_paragraph_styles.push(doc.paragraphStyles[i]);
for(var i = 0; i < doc.paragraphStyleGroups.length; i++) {
          for(b = 0; b < doc.paragraphStyleGroups[i].paragraphStyles.length; b++) {
                    list_of_paragraph_styles.push(doc.paragraphStyleGroups[i].name+"->"+doc.paragraphStyleGroups[i].paragraphStyles[b].name);
                    all_paragraph_styles.push(doc.paragraphStyleGroups[i].paragraphStyles[b]);
// Make the dialog box for selecting the paragraph styles
var the_dialog = app.dialogs.add({name:"Section start at paragraph style:"});
with(the_dialog.dialogColumns.add()){
          with(dialogRows.add()){
                    staticTexts.add({staticLabel:"Find:"});
          with(borderPanels.add()){
                    var find_first_paragraph = dropdowns.add({stringList:list_of_paragraph_styles, selectedIndex:0});
with(dialogRows.add()){
                    staticTexts.add({staticLabel:"Apply Master:"});
          with(borderPanels.add()){
                    var change_master = dropdowns.add({stringList:list_of_masters_names, selectedIndex:0});
                    staticTexts.add({staticLabel:"Select \"undefined\" not to change"});
the_dialog.show();
// Define paragraph styles
var myParagraph = all_paragraph_styles[find_first_paragraph.selectedIndex];
var myMaster=(list_of_masters_names[change_master.selectedIndex]!="undefined")?list_of_masters[change_master.selectedIndex]:null;
app.findChangeGrepOptions.includeFootnotes = false;
app.findChangeGrepOptions.includeHiddenLayers = false;
app.findChangeGrepOptions.includeLockedLayersForFind = false;
app.findChangeGrepOptions.includeLockedStoriesForFind = false;
app.findChangeGrepOptions.includeMasterPages = false;
app.findGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.appliedParagraphStyle = myParagraph;
var myFound=doc.findGrep();
var i=myFound.length;
var pBar = new ProgressBar("Sectioning");
     pBar.reset("Rabdare...", i);
while (i--)
        pBar.hit();
        if (myFound[i].parentTextFrames[0].parent.constructor.name=="Character"){
            var myPage=myFound[i].parentTextFrames[0].parent.parentTextFrames[0].parentPage;}
        else{
     var myPage=myFound[i].parentTextFrames[0].parentPage;}
     var mySection;
     if (myPage.appliedSection.pageStart==myPage){mySection=myPage.appliedSection;}
     else{
     doc.sections.add(myPage,{pageNumberStart:1})};
    // mySection.pageStart=myPage;
     //mySection.pageNumberStart=1;
     if (myMaster) {myPage.appliedMaster=myMaster};
alert("Acum e gata!!");
app.doScript('main()',undefined,undefined,UndoModes.entireScript,'AutoSections');
//main();

Similar Messages

  • How to display page no for different master pages in one adobe form application

    Hi All,
    we have requirement where we need to  display page nos in different master pages in one single adobe form.
    For the First form the page nos should be displayed pgno of total pages and for 2nd form the page no shuld be displayed as pgno of total pg.
    so please help me with any script or suggestions for displaying the page no accordingly in different master pages. Your suggestions are greatly appreciated.
    Thanks
    Raja.

    Hi Lingaraj,
    We have 2 different Master pages and 2 Body pages. For the seccond Master page the page no are comming correct like 1 of 3 ,2 of 3 and 3 of 3 but for First master page the page no are comming 0 of 3  in all of the page its not displaying the current page no in 1st master page.
    Screen shots are attached for first master page and Hierarchy Node.Pls see the highlighted section in 2nd image.
    Pls see and suggest me accordingly. Hope this helps are let me know anything u require.

  • What to do if my master page is too small for custom master page column, I need to change the papers

    What to do if my master page is too small for custom master page column, I need to change the papersize from A4 to US letter size *

    My 2nd gen works fine with WPA2 and AES encryption.
    You may need to go back and start over.  Reset the router back to factory defaults, log on as the admin, set up security, DHCP, and make sure the IP address pool has enough IP addresses to lease to ALL of the computers/devices that will connect to that the router.

  • Script for Applying master Spread

    Hi,
    This Script is for Applying CO-Opener master page  wherever CN is applied, When we run the script, it alerts Sucess.But master spread is not applied . Please resolve.
    var mydoc=app.activeDocument;
    var mypara = mydoc.stories.item(0).paragraphs.everyItem().getElements();
    for(i=0; i<mypara.length; i++){
        if (myPara[i].appliedParagraphStyle.name=="CN"){
               mypara[i].parentTextFrames[0].parent.appliedMaster = mydoc.masterSpreads.item("CO-Opener");
    alert("Master Page applied Sucessfully")

    Hi Math,
    I hope your coding is correct, but it seems stories[0] do not have "CN" Styles.
    Change the below line:
    var mypara = mydoc.stories.item(0).paragraphs.everyItem().getElements(); 
    into
    var mypara = mydoc.stories.everyItem().paragraphs.everyItem().getElements(); 
    Thanks to Jongware and Green4ever.....
    and also the use the below url to get the correct coding for CS4 and CS5 and above
    Apply Master Page using Paragraph Style
    var myDocument = app.activeDocument; 
    var myParas = myDocument.stories.everyItem().paragraphs.everyItem().getElements(); 
    var myPage = myDocument.pages; 
    for(i=0; i<myParas.length; i++) 
        if(myParas[i].appliedParagraphStyle.name == "CT") 
            //Works only in CS5 and later 
            myParas[i].parentTextFrames[0].parentPage.appliedMaster = myDocument.masterSpreads.item("B-Master"); 
            //for CS4 use this 
            //myParas[i].parentTextFrames[0].parent.appliedMaster = myDocument.masterSpreads.item("B-Master"); 
    Regards
    Siraj

  • Load different css for one master page in different variation labels

    Hi
    i have two variation label in my SharePoint 2013 site collection
    one for English language 
    and one for the Arabic language 
    i have used the twitter bootstrap so now i have one master page and one style file for the two sites
    i need to load custom css for Arabic to handle the RTL so how can load English style and Arabic style 
    should i use cssregistration and how 
    or any suggestion please :)

    Hi,
    We can use jQuery to add the css file based on some conditions, the following code for your reference:
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.11.2.min.js"></script>
    <script type="text/javascript">
    $( function() {
    if ($("#label1").val()== "English") {
    $("<link href='css/custom-en.css' rel='stylesheet' type='text/css' />").appendTo('head');
    } else if ($("#label2").val() == "Arabic") {
    $("<link href='css/custom-ar.css' rel='stylesheet' type='text/css' />").appendTo('head');
    </script>
    Best Regards
    Dennis Guo
    TechNet Community Support

  • Script add/delete master page automatically

    I've searched and haven't managed to find one so apologise if this has been asked before.
    Adobe Indesign CS2
    Does anyone have a script to automatically insert, or delete my master page with an automatic text link between the frames on my pages, as I am loosing too much time adding and deleting manually. The page is my 'A-Master'
    I have never installed a script before, nor know how to but I must invest time in this as it will save me lots of time in the future with the programming behaving like a word processor (microsoft word) with the beauty of the design elements with indesign.
    Regards

    Are you looking for some sort of feature that adds pages and link the text automatically as you type and reach the end of a page? That isn't going to happen in CS2, even with a script, as far as I know. There might be a plugin available, but it won't be free.
    You'd be better off upgading while you still can get upgrade pricing. Smart Text Reflow was introduced in CS4 and does exactly what I think you want.

  • How do I create an underlying master page for my master pages (without messing them up)?

    I created a Muse site long ago, and wanted to fix my SEO easily overall by better analytics among other things.
    Perhaps I am doing this the wrong way but I was thinking I could create a master page that I could just drop the html I needed into, and thus not fuss too much with my other pages. The problem is I already have master pages that my site is based on (before you could do this), and it would be much easier to have those master pages stem from one source (a Master master page?).
    Everytime I try to do this it changes my current master and final pages. Anyway I can create and invisible master so this doesn't happen?
    What should I do instead?
    THANK YOU.
    William

    Thanks,
    Your intructions were my plan untill I realized that in doing so, it changed the backgrounds etc of my current masterpages. I realize that this is a lack of planning due to my very rusty design principles, and something I wouldn't have done in my day job if the features had been in place. (so thank you for the new features!) 
    While I realize I could probably fix this by recreating the site with a uniform underlying Primary Master Page feeding into my Secondary Master Pages, I was trying to create a master page that in effect wouldn't change a thing in the other subservient masterpages (thus allowing me freedom to create groups of pages with common analytics or any other types of code).
    Simply when I take your suggestion, things change... can I do this without making things change?
    Not sure if this makes sense. I am trying to avoid coding or a overhaul b/c of time constraints.
    William

  • CS5: Watch out for a master page bug

    I found a pretty serious bug in CS5. I opened a catalog I created with CS4, which has master pages for page frames. I also have occasional left or right title pages which have no frames, and [none] selected as master.
    Elements aligned to spread center on right or left page will sometimes appear on the spread even if the page has [none] as master, but the facing page has a master applied.
    This is difficult to explain, but it seems that the new page system has messed up something and CS5 thinks the element is overlapping both master pages, even tho it's only aligned to center. If I nudge the element by 0,01 mm away from center, it will disappear from the facing page.
    Check your layouts before sending to print.

    How exactly would that work?
    I export from CS4 and open the exported to CS5?
    or
    I open the CS4 document in CS5, export and re-load exported to again CS5?

  • What is the best practice for creating master pages and styles with translated text?

    I format translated text all the time for my company. I want to create a set of master pages and styles for each language and then import those styles into future translated documents. That way, the formatting can be done quickly and easily.
    What are the best practices for doing this? As a company this has been tried in the past, but without success. I'd like to know what other people are doing in this regard.
    Thank you!

    I create a master template that is usually void of content, with the exception I define as many of the paragraph styles I believe can/will be used with examples of their use in the body of the document--a style guide for that client. When beginning a new document for that client, I import those styles from the paragraph styles panel.
    Exception to this is when in a rush I begin documentation first, then begin new work. Then in the new work, I still pull in those defined paragraph and or object styles via their panels into the new work.
    There are times I need new styles. If they have broader applicability than a one-off instance or publication, then I open the style template for that client and import that style(s) from the publication containing the new style(s) and create example paragraphs and usage instructions.
    Take care, Mike

  • Tips for making master pages??

    Hello,
    I am making a master page that will contain jpeg images, and I am having trouble getting them to "snap to" the guides". Before, in CS3, I remember when I moved an image close to a guide, it would automatically "snap to" it, but for some reason that doesn't seem to always happen here. I am not using the baseline or other grids at all, I have made guides. The guides are two perpendicular lines, and try to snap them to the right angle formed by the lines.
    Hope that explanation wasn't confusing. I just want to find a good way to set up my master page and to establish guides. It is possible to use the "snap to" with guides alone and not the grids, right? To get rid of the grids I set the spacing for the lines for very large distances so they wouldn't appear at all.
    Cheers for any assistance in advance...

    Hello,
    Thanks for the replies. The "snap to" option is on, as well as the "guides in back" option. What will happen is, I drag an image within range of the guide (I'm not using a grid) and it will be very close, but I often have to adjust it slightly, for example (I have it set for inches as the unit of measurement) I want one image to be at  the guideline, which is .7817 but too I dragged (drug?) near to the guide ended u at .7823. Once I get this close to the guide, shouldn't the snap to" take over? BTW, my "snap to" zone is 12px.
    I see that both "align to object edge" and "align to object center" are checked... should I uncheck "align to object center"?

  • Scripts for Exporting Master/Work Rep

    Hi,
    I want to automate the export process and in turn was looking for any scripts for exporting the whole ODI Work/Master Rep. I checked the CLASS objects and we donot have any CLASS names for Repository exports.
    Thanks in advance for any answers..!

    Created for 10g [ http://odiexperts.com/automize-the-backup-using-odi-exports]
    but should work for 11g too :)

  • Using Expression Web for editing master pages

    I have SP Foundation 2013 and I am trying to edit a master page in Expression web since SP Designer no longer has design view. Reading the documentation it says that any HTML tools such as dreamweaver, Expression Web etc can be used.
    I have mapped a drive to the Master Page Gallery and made a copy of the master page I am trying to edit.
    When I open it up in Expression Web I get the following error:
    Error creating Control - SPHtmlTag
    Unknown Server Tag Sharepoint:SPHtmlTag
    Can anyone help? I'm by far no web developer or Sharepoint Developer and I just want to make some simple changes to the master page such as adding a footer with some links/images etc so it displays on all pages within the site, which is just a basic intranet
    site for a small company.
    Any help would be appreciated, thanks.

    you use HTML tools such as dreamweaver to desgin the .html file associated with the .master file:
    http://blogs.technet.com/b/speschka/archive/2012/07/27/using-dreamweaver-and-design-manager-with-sharepoint-2013.aspx
    GuYuming
    TechNet Community Support

  • The type inside the footer drops down 50 px below the bottom of page in preview mode. I already tried unchecking the sticky footer in the site properties for that master page.

    I need to fix this footer text on the home page. The type on the master page is centered inside a white 50px box. But in preview mode, the line of text drops 50px down below the bottom of page. I unchecked the sticky footer in the site properties and also set the line of text as footer item. The setting was the same on my second master and it comes out fine.

    Hi
    The "content" div is styled to have 100px height and visible overflow. So the text is overflowing the div but the footer is  "unaware" / ingoring it and positions itself after "sidebar2"
    Change the height of "content" to 100% and it should work.
    Kind Regards,
    Alex

  • Script for extracting multiple pages

    Hi,
    I'm working with the default "extract pages" script: http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_A croJS.88.465.html
    I want to modify it to extract 2 pages at a time.  For example, say I start with a 6-page document.  I would like the script to extract pages 1,2 as one document, then pages 3,4 and 5,6.
    How would I modify the script to do this?
    Thanks!

    You could use a loop, but you don't need to for what you want. Do something like:
    // Extract first two pages to a new file
    extractPages({nStart: 0, nEnd: 1, cPath: "/F/temp/file1.pdf"});
    // Extract 3rd and 4th pages
    extractPages({nStart: 2, nEnd: 3, cPath: "/F/temp/file2.pdf"});
    // Extract fifth and sixth pages
    extractPages({nStart: 4, nEnd: 5, cPath: "/F/temp/file3.pdf"});
    Obviously, you need to change the file paths.

  • Script for printing changed pages only

    Does anyone know of a script that will allow the printing of only those pages that have had changes made to them since a previous save? I'm a typesetter doing work only on books and journals and sometimes it's a bit tedious to keep track of the individual pages one works on. thanks,

    Ok,
    Here is a raw code. All you need to do is edit the script to specify the printer preset you want to use. I don't have a printer my self to debug but I think it should work.
    Here is the idml to grab the object styles. Don't forget to apply on objects located onto the pasteboard. The script look for these objects and grab the page name next to them to finally print these pages.
    Hope it helps,
    Loic
    function main(){
              var doc,
              changedArray = [],
              changedStyle,
              unchangedStyle,
              i=0,
              max=0,
              found = [],
              pagerange = [];
              obj,
              vb,
              leftPage,
              leftPageBounds,
              rightPage,
              rightPageBounds,
              pagerange = "";
              if(!app.documents.length){ return; }
              var doc = app.activeDocument;
              changedStyle = doc.objectStyles.itemByName("changed");
              unchangedStyle = doc.objectStyles.itemByName("unchanged");
              if(!changedStyle.isValid ||  !changedStyle.isValid){
                        alert("Problem with object styles. Script requires both \"changed\" and \"unchanged\" styles.");
                        return;
              app.findObjectPreferences.appliedObjectStyles = changedStyle;
              found = doc.findObject();
              max = found.length;
              for(i=0; i<max; i++){
                        obj = found[i];
                        vb = obj.visibleBounds;
                        leftPage = obj.parent.pages[0];
                        leftPageBounds = leftPage.bounds;
                        rightPage = obj.parent.pages[-1];
                        rightPageBounds = rightPage.bounds;
                        if(vb[1]>rightPageBounds[1]){
                                  pagerange.push(rightPage.name);
                        else if(vb[1]<leftPageBounds[1]){
                                  pagerange.push(leftPage.name);
              app.printPreferences.activePrinterPreset = app.printerPresets.itemByName("my printer preset");
              var oldPrintPrefs = doc.printPreferences.pageRange;
              doc.printPreferences.pageRange = pagerange.join(",");
              alert("Gone printing");
              app.print();
              doc.printPreferences.pageRange = oldPrintPrefs;
    main();

Maybe you are looking for

  • IOS 8.1 Excel % Issue

    Hi Applemates, With the update to 8.1 (from 7.1) on my iPhone & iPad, I am having issues reading my Excel reports that come through mails. The issue is the % numbers are shown incorrectly. E.g. 39% is shown as 0%, 90% is shown as 1% and 200% is shown

  • Reorganization of DB

    how we can do reorganization the db, what need to be reorg? what the best practice for doing reorg?

  • Autocorrect sentence in quotes in word 2007?

    When i start a sentence in quotes and the first letter of the first word is not capitalized it doesn't correct the first word. For example: "this is a blue color." doesn't autocorrect it to "This is a blue color." Can i make Word autocorrect the firs

  • Legend Text Wrapping

    Is it possible to wrap the legend text for a combination chart? I am placing the legend at the bottom of the chart and have long series names that scroll out of the object box.

  • How do I disable ports with Nvidia Firewall?

    Trying to get this Nvidia firewall so it secure. Can ya help me set it up? I tried the symantech site and it says I am full of holes!! 445 Windows NT / 2000 SMB. A standard used to exchange Server Message Blocks, and can be exploited in multiple ways