Skip to content

Instantly share code, notes, and snippets.

View indiscripts's full-sized avatar

Marc Autret indiscripts

View GitHub Profile
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)
// 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 =
[
(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;
@indiscripts
indiscripts / TestDoScriptFromModal.jsx
Created February 2, 2021 15:26
Test app.doScript from InDesign's modal state
// 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';
@indiscripts
indiscripts / ScriptUIScalingTest.jsx
Created March 7, 2021 20:36
Testing UI Scaling vs. ScriptUI in Windows10
(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;
// 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];
})();
// 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
#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};
@indiscripts
indiscripts / PageToRangeTest.jsx
Created November 25, 2021 16:45
PageToRange function
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));
};
@indiscripts
indiscripts / halo.idms
Created March 3, 2022 02:48
PastedSmoothShade Example
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?aid style="50" type="snippet" readerVersion="6.0" featureSet="257" product="17.0(105)" ?>
<?aid SnippetType="PageItem"?>
<Document DOMVersion="17.0" Self="d">
<PastedSmoothShade Self="PastedSmoothShade/ude" ContentsVersion="0" ContentsType="RadialShade" SpotColorList="" ContentsEncoding="Ascii64Encoding" ContentsMatrix="1 0 0 1 0 0" Name="$ID/" ColorEditable="true" ColorRemovable="true" Visible="false" SwatchCreatorID="7937" SwatchColorGroupReference="n">
<Properties>
<Contents><![CDATA[QA+hbGAAAAAAAAAAAAAAAL/iNOEgAAAAQA9TSsAAAABAgsDVoAAAAEBjbRaAAAAAAAEAAQAAAAAA
AAACAAAABAAAAAAAAAABAAAAAQAAAAAAAQAAAAAAAAAAP/AAAAAAAAAAAAAAAAEAAAAAAAAAAD/w
AAAAAAAAAAAAAQAAAAEAAAAAAAAAAEB7IAAAAAAAAAAAAQAAAAAAAAAAP/AAAAAAAAAAAAAAAbMA
AAAIAAABs1BQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFFRUVFR