Skip to content

Instantly share code, notes, and snippets.

@indiscripts
Created February 22, 2023 17:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save indiscripts/518d3dbe8570548055ddc4d5d91150e6 to your computer and use it in GitHub Desktop.
Save indiscripts/518d3dbe8570548055ddc4d5d91150e6 to your computer and use it in GitHub Desktop.
InDesign script: Prompts a warning if the inside/left slug of the opened document is less than `MIN_SLUG`
(function(/*any*/ev, ff,t,cond,bk,pf,x)
//----------------------------------
// [This InDesign script CAN be used as a startup script.]
// Prompts a warning if the inside/left slug of the opened document is less than `MIN_SLUG`.
// Targeted event: afterOpen (app listener)
{
const MIN_SLUG = 130; // in mm
const MM = +MeasurementUnits.MILLIMETERS;
if( (ev||0).isValid )
{
cond = 'afterOpen' == ev.eventType // Make sure you're managing the right event
&& (!app.modalState) // app.modalState would cause `alert` to fail.
&& 'LayoutWindow'==(t=ev.target).constructor.name // ev.target must be a LayoutWindow (not a document)
&& (t=t.parent).isValid // Valid document required.
&& (t.properties.saved||t.properties.converted) // Want saved or converted docs (excl. recovered and unsaved ones).
;
if( cond )
{
pf = app.scriptPreferences;
MM == (bk=+pf.measurementUnit) ? (bkp=0) : (pf.measurementUnit=MM);
x = parseFloat(t.documentPreferences.slugInsideOrLeftOffset);
bk && (pf.measurementUnit=bk);
if( x < MIN_SLUG ) alert( "The left slug area ("+x+") is less than "+MIN_SLUG+"mm." );
}
}
else
{
// Install the event listener (if not yet installed).
// ---
const UID = 'myCheckSlugHandler';
(ff=File($.fileName)).exists
&& !((t=app.eventListeners).itemByName(UID)).isValid
&& ((t.add('afterOpen',ff)).name=UID);
}
})($.global.evt);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment