Skip to content

Instantly share code, notes, and snippets.

View indiscripts's full-sized avatar

Marc Autret indiscripts

View GitHub Profile
@indiscripts
indiscripts / IndexPath.jsx
Last active July 6, 2023 19:45
Returns a item-to-subitem path strictly based on `index` access
// InDesign script (function) -- DRAFT [230706]
// Cf https://community.adobe.com/t5/indesign-discussions/indesign-script-keep-reference-of-nested-pageitem-in-group-while-duplicating-it/td-p/13917002
function indexPath(/*PageItem*/child,/*PageItem*/root,/*bool=0*/AS_SPEC, a,t,p,rk,tk,pk,i,o,x,s)
//----------------------------------
// Assuming that `root` is a parent of `child` in the DOM hierarchy, returns
// a root-to-child path in the form of a `.<collection>[<index>]` sequence,
// each element being introduced by '.', e.g. `.textFrames[1].ovals[2].textFrames[0]`
// The result is then that `child === root.textFrames[1].ovals[2].textFrames[0]`
// ---
@indiscripts
indiscripts / TestEventsPriority.jsx
Created June 29, 2023 11:25
Illustrates the distinctive priority of USER vs. PROGRAMMATIC events in ScriptUI
(function testEventsPriority( w,g)
//----------------------------------
// ScriptUI CS/CC - Modal dialog.
// Illustrates the distinctive priority of USER vs. PROGRAMMATIC events.
{
// Global mousedown/mouseup listener.
const ON_MOUSE = function(ev, t)
{
// this :: Window
if( (ev.target.properties||0).NoEvent ) return; // Used for the [Clear] action.
@indiscripts
indiscripts / checkSlug.jsx
Created February 22, 2023 17:32
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 )
@indiscripts
indiscripts / checkEmbed.jsx
Last active February 22, 2023 20:32
InDesign script: Prompts a warning if some embedded links exist in the doc before saving
(function(/*any*/ev, ff,t,cond,s,z)
//----------------------------------
// [This InDesign script CAN be used as a startup script.]
// Prompts a warning if some UNembedded links exist in the doc;
// the save/saveAs task is then interrupted.
// [FIX230222] Made a confusion on the script purpose:
// now detect UNembedded links!
// Targeted events: beforeSave|beforeSaveAs
{
const EMBD = LinkStatus.LINK_EMBEDDED.toString();
@indiscripts
indiscripts / SelPlacePDFPage.jsx
Created January 16, 2023 10:20
InDesign script: change Page in placed PDF (selection)
;(function selPlacePDFPage( dt,doc,sel,t,ok,ff)
//----------------------------------
// Simple interface for changing page in placed PDF.
// (Just select the PDF container and run.)
{
dt = +new Date;
try
{
doc = app.properties.activeDocument;
if( !doc ) throw "No active document.";
// InDesign script (DRAFT.)
//----------------------------------
// Apply some text conversion routine on consistent
// style ranges *while preserving special characters*
// (anchored objects, tables, footnotes...)
function myConverter(/*str*/text)
//----------------------------------
// Change a string into something else...
@indiscripts
indiscripts / NL_Date.jsx
Created August 19, 2022 00:23
Localized Date variable (NL)
#targetengine 'usernameVariable'
if( 'function' != typeof( $.global.afterOpenHandler ) )
{
afterOpenHandler = function(/*afterOpenEvent*/ev, doc,dt,str)
//----------------------------------
{
doc = ev.target;
if( 'Document' != doc.constructor.name ) return;
@indiscripts
indiscripts / suiSecret.jsx
Created August 16, 2022 09:51
Testing ScriptUI 'Secret Key' in Listbox (CC)
// Hiding secret keys in listbox
// (ScriptUI CC Only.)
// ---
var dlg = new Window('dialog');
var lst = dlg.add('group').add('listbox',void 0,
[
'item1' + '\0secretKey1',
'item2' + '\0secretKey2',
'item3' + '\0secretKey3',
'item4' + '\0secretKey4',
@indiscripts
indiscripts / TestStaticTextlink.jsx
Created August 4, 2022 06:32
Basic StaticText Hyperlink Scheme
@indiscripts
indiscripts / graphicCellObjectBox.jsx
Created August 2, 2022 06:19
Testing GCO-to-BOX solution
function graphicCellObjectBox(/*PageItem*/gco, dup,t,lt,rb,xy,dx,dy)
//----------------------------------
// [DRAFT220802] Input: PageItem of a graphic cell.
{
const AP_CC = +AnchorPoint.CENTER_ANCHOR;
const AP_TL = +AnchorPoint.TOP_LEFT_ANCHOR;
const AP_BR = +AnchorPoint.BOTTOM_RIGHT_ANCHOR;
const CS_IN = +CoordinateSpaces.INNER_COORDINATES;
const CS_PAR = +CoordinateSpaces.PARENT_COORDINATES;