Skip to content

Instantly share code, notes, and snippets.

Avatar

Marc Autret indiscripts

View GitHub Profile
View PageToRangeTest.jsx
const PageToRange = function(/*uint>0*/p, q)
//----------------------------------
// Returns the 1-based range index containing page number `p`.
// (The last range supports any `p` beyond the maximum.)
// [REM] Use PageToRange.setup() to initialize the ranges.
// ---
// => uint [1 for 1st range, 2 for 2nd range...] | false [INVALID p]
{
return p > 0 && ((q=callee.Q).charCodeAt(-1+p)||q.charCodeAt(-1+q.length));
};
View InteractingPalettesExample.jsx
#targetengine 'StyleToGrep'
// Experimental InDesign/ExtendScript/ScriptUI code for testing the idea of two interacting palettes.
// Discussion: https://community.adobe.com/t5/indesign/what-is-the-best-practices-to-call-palette-from-another-dialog/td-p/12154542
// [DISCLAIMER] The below script is just a quick proof of concept. Do not use it in production.
if( 'function' != typeof $.global.StyleToGrep )
{
Object.prototype.setup=function(o,k){for(k in o)o.hasOwnProperty(k)&&(this[k]=o[k]);return this};
View ExportFile_Issue_Depending_onSel.jsx
// Assuming a text is selected (or cursor positioned) in a TextFrame.
// ---
var tf = app.selection[0].parentTextFrames[0];
alert( tf.constructor.name ); // => TextFrame expected.
var dup = tf.duplicate(); // Duplicate the frame
dup.properties = { // Assign some props
contents:'test',
textFramePreferences:{ignoreWrap:true},
locked:false
View ScriptUIScalingFactor
// This routine is part of IdExtenso framework.
// ---
ScriptUI.SCALING = (function(w)
{
(w=new Window('palette','')).margins=0;
w.add('group').minimumSize=[500,500];
w.layout.layout(1);
return [w.size[0]/500,w.size[1]/500];
})();
@indiscripts
indiscripts / ScriptUIScalingTest.jsx
Created Mar 7, 2021
Testing UI Scaling vs. ScriptUI in Windows10
View ScriptUIScalingTest.jsx
(function( w,t)
//----------------------------------
// Testing UI Scaling vs. ScriptUI in Windows10
{
w = new Window('dialog',"test");
w.margins = 60;
w.orientation = 'column';
(w.blue = t = w.add('group')).minimumSize = [600,400];
t.margins = 40;
@indiscripts
indiscripts / TestDoScriptFromModal.jsx
Created Feb 2, 2021
Test app.doScript from InDesign's modal state
View TestDoScriptFromModal.jsx
// Test app.doScript from InDesign's modal state
// - Run this jsx from your Scripts panel and click`Test`
// - Feedback here: https://twitter.com/indiscripts
// ---
(function(w,s,u)
{
const V = "ID " + app.version + " / " + $.os;
w = new Window('dialog',"Test doScript in Modal State");
w.orientation = 'row';
View findAll.jsx
(function(t,a,w,k,i,ff)
//----------------------------------
// InDesign script.
// Show Grep/Text found items into a file.
{
a = (t||0)&&('string'==typeof(app[(k='findGrep')+'Preferences'].findWhat)||'string'==typeof(app[(k='findText')+'Preferences'].findWhat));
if(!a ) return;
w = new Window('palette',k);
w.margins = 25;
View Lines-TextStyleRanges-with-everyItem
// Having a text frame selected.
// ---
var tf = app.selection[0];
var lines = tf.lines.everyItem().contents;
var ranges = tf.textStyleRanges.everyItem().contents;
var lines_ranges = tf.lines.everyItem().textStyleRanges.everyItem().contents;
var result =
[
View Group.prototype.addItems.jsx
Group.prototype.addItems = function(/*PageItem[]*/newItems)
//----------------------------
// Emulates Group.groups.add(items)
// [ Also supports Group.addItems(existing_item) ]
// <newItems> == Array of 2+ PageItem
// -> create a <newItems> subgroup in <this>
// <newItems> == single PageItem
// -> add the PageItem in <this>
// Returns the added subgroup or item
// (the whole group hierarchy is preserved)