As part of our project to automate the creation of an EPub using Adobe InDesign CS6, the document skeleton is created using a script. This requires a document preset and a stylesheet.

In this blog, we create the document preset for the project. With two exceptions, all of the properties for the document preset are “hard-wired” in the script. The two properties the user is allowed to enter in a custom dialog are the name of the preset, and its page orientation. For our purpose here, we will establish these values at the top of the script rather than use the custom dialog. The script checks for the existence of the document preset and creates the preset using the name supplied. For the sake of readability and to make the script easier to edit, the properties for the preset are set using separate statements.

APPLESCRIPT

try
	set presetName to "TestEPub" --substitute name of preset here
	set pageOrient to 0 --0 indicates portrait; 1 indicates landscape 
	set docPreset to createEpubPreset(presetName, pageOrient)
on error errStr
	activate
	display alert errStr
end try
(*Creates document preset. All values except preset name and page orientation are
established within the routine.*)
on createEpubPreset(presetName, pageOrient)
	tell application "Adobe InDesign CS6"
		if not (exists document preset presetName) then
			set presetRef to make document preset with properties {name:presetName}
			tell presetRef
				set create primary text frame to true
				set intent to web intent
				set document bleed top offset to 0
				set document bleed uniform size to true
				set column count to 1
				set column gutter to "12 px"
				set top to "48 px"
				set left to "36 px"
				set right to "36 px"
				set bottom to "36 px"
				set pages per document to 1
				set page height to "600 px"
				set page width to "512 px"
				set slug top offset to 0
				set document slug uniform size to true
				set start page number to 1
				set facing pages to false
				set page size to "Custom"
				if pageOrient = 1 then
					set page orientation to landscape
				else
					set page orientation to portrait
				end if
				
			end tell
		else
			set presetRef to document preset presetName
		end if
	end tell
	return presetRef
end createEpubPreset

EXTENDSCRIPT

try {
        var presetName = "TestEPub"; //substitute your name here
        var pageOrient = 0; //0 indicates portrait; 1 indicates landscape
        var docPreset = createEpubPreset(presetName, pageOrient);
    } catch (e) {
        alert (e);
    }
/*Creates document preset using values entered by user*/
function createEpubPreset (presetName, pageOrient) {
    if (app.documentPresets.itemByName (presetName).isValid) {
        alert ("preset exists");
        return app.documentPresets.itemByName(presetName);
    } else {
        var presetRef = app.documentPresets.add({name: presetName});
   }
    with (presetRef) {
        createPrimaryTextFrame = true;
        webIntent = DocumentIntentOptions.WEB_INTENT;
        documentBleedTopOffset = 0;
        columnCount = 1;
        columnGutter = "12 px";
        top = "48 px";
        left = "36 px";
        right = "36 px";
        bottom = "36 px";
        pagesPerDocument = 1;
        pageHeight = "600 px";
        pageWidth = "512 px";
        slugTopOffset = 0;
        documentSlugUniformSize = true;
        startPageNumber = 1;
        facingPages = false;
        pageSize = "Custom";
        if (pageOrient == 1) {
            pageOrientation = PageOrientation.LANDSCAPE;
        } else {
            pageOrientation = PageOrientation.PORTRAIT;
        }
    }
    return presetRef;
}

Notice how the with statement in ExtendScript works similar to the tell statement in AppleScript.

Any time you have a project that requires a document preset having pre-established values, this script could be modified for that purpose. Using a script such as this makes sure that documents within a project have the same settings, assuring consistency throughout.