Copy link to clipboard
Copied
Is there a reason why this script works fine in Mac OS "High Sierra", but slows down Indesign to a crawl in "Sierra"? When i open the script in the editor i get this error:
// https://forums.adobe.com/thread/2049382
// Main script by Loic Aigon Add highly customized Text Variables to InDesign | Ozalto
// Additions (First Page Dimensions and variable update on script execution)
// and modifications (without permission, sorry Loic) by Trevor http://www.creative-scripts.com
#targetengine 'usernameVariable'
//This function adds static text variables in InDesign
//They won't be dynamically updated though.
//That's why we need the updating function below
function toTitleCase(s) { // By Trevor
return s.toLowerCase().replace(/\b\w/g, function () {return arguments[0].toUpperCase()});
}
function myRound(thisNumber, digits) { // By Trevor
digits = (digits) ? Math.pow(10, digits) : 1000;
return Math.round(thisNumber * digits) / digits;
}
function addVariables(openEvent){
if (!openEvent) return;
var doc = (openEvent.constructor == Document) ? openEvent : openEvent.parent; // By Trevor
while ( doc.constructor.name != "Document" )
{
if ( doc.constructor.name == "Application" ){ return; }
doc = doc.parent;
}
//Adding User name to text variables
createTextVariable(doc, "User name", $.getenv($.os[0] == "M" ? "USER" : "username") ); // changed by Trevor
//Adding Computer name to text variables
createTextVariable(doc, "HD Name", (Folder.system).parent.displayName );
//Adding Computer name to text variables
createTextVariable(doc, "Computer Name", getComputerName() );
//Adding a link to my website
createTextVariable(doc, "_About Loic Aigon", "Feel free to visit my website: http://www.loicaigon.com !" );
//Adding a link to my website
createTextVariable(doc, "_About Trevor", "Feel free to visit my website: http://www.creative-scripts.com !" ); // by Trevor
//Adding First Page Dimensions
createTextVariable(doc, "First Page Dimensions", getPageDimentions(doc.pages[0])); // by Trevor
//Adding Bleed
pagesize = app.activeDocument.textVariables.itemByName("Bleed");
pagesize.variableOptions.contents = ('' + app.activeDocument.documentPreferences.documentBleedBottomOffset + " in")
//Adding Margins
pagesize = app.activeDocument.textVariables.itemByName("Margins");
pagesize.variableOptions.contents = ('' + app.activeDocument.layoutWindows[0].activePage.marginPreferences.left + " in")
}
addVariables(app.properties.activeDocument); // callback by Trevor
//Generic function to add static custom text variables
function createTextVariable(target, variableName, variableContents){
var usernameVariable = target.textVariables.itemByName(variableName);
if(!usernameVariable.isValid){
usernameVariable = target.textVariables.add();
usernameVariable.variableType = VariableTypes.CUSTOM_TEXT_TYPE;
usernameVariable.name = variableName;
}
usernameVariable.variableOptions.contents = variableContents;
}
//Snippet for grabbing the deep name of the computer
function getComputerName(){ // by Trevor
return $.os[0] == "M" ? app.doScript("get computer name of (system info)", ScriptLanguage.APPLESCRIPT_LANGUAGE) : $.getenv("computername");
}
function getPageDimentions(page){ // by Trevor
var width, height, bounds, units, decPlaces;
// function presumes that normal pages
// i.e. same vertical and horizontal and no page shape transformations
decPlaces = 4;
units = toTitleCase(page.parent.parent.viewPreferences.horizontalMeasurementUnits.toString()); // If you forgot to include the toTitleCase function then remove the method
bounds = page.bounds;
height = bounds[2] - bounds[0];
height = myRound(height, decPlaces);
width = bounds[3] - bounds[1];
width = myRound(width, decPlaces);
return width + " X " + height + " " + units
}
//Add listeners to update file when opened.
app.addEventListener('afterOpen', addVariables);
// You might like to add some or all of these to make the update better
app.addEventListener('beforeSave', addVariables); // by Trevor
app.addEventListener('beforeSaveAs', addVariables); // by Trevor
app.addEventListener('beforeSaveACopy', addVariables); // by Trevor
app.addEventListener('beforeExport', addVariables); // by Trevor
app.addEventListener('beforePrint', addVariables); // by Trevor
app.addEventListener('beforeDeactivate', addVariables); // by Trevor
app.addEventListener('afterActivate', addVariables); // by Trevor
Copy link to clipboard
Copied
Hi attil ,
this error is no error in ExtendScript. Use the ESTK ( ExtendScript Toolkit App ) for debugging. Not ES Lint.
FWIW: This thread should be moved over to:
Regards,
Uwe
Copy link to clipboard
Copied
I cannot get ExtendScript Toolkit App to install on the mac that has Sierra OS on it so i had to use another editor.
Copy link to clipboard
Copied
attil wrote
I cannot get ExtendScript Toolkit App to install on the mac that has Sierra OS …
Why is that? Any error messages?
Regards,
Uwe
Copy link to clipboard
Copied
Yes, "failed to initialize"
Copy link to clipboard
Copied
I would open a new thread with your ESTK installer problems here:
Creative Cloud Download & Install
Regards,
Uwe