Skip to content

Instantly share code, notes, and snippets.

View grefel's full-sized avatar

Gregor Fellenz grefel

View GitHub Profile
@grefel
grefel / renameSwatches.jsx
Last active January 25, 2021 19:45
Rename Swatch if possible
var dok = app.activeDocument;
for (var i = 0; i < dok.swatches.length; i++) {
try {
dok.swatches[i].name = "prefix" + dok.swatches[i].name;
}
catch(e) {
// could not rename
}
}
@grefel
grefel / rotateSpreads.jsx
Created July 31, 2019 13:10
Reset Spread Rotation
var matrice = app.transformationMatrices.add(1,1,0,0,0,0);
spread.transform(CoordinateSpaces.PASTEBOARD_COORDINATES, AnchorPoint.CENTER_ANCHOR, matrice, [MatrixContent.ROTATION_VALUE, MatrixContent.SCALE_VALUES, MatrixContent.SHEAR_VALUE]);
// Based on https://github.com/indiscripts/extendscript/blob/master/scriptui/ProgressBar.jsx
$.hasOwnProperty('ProgressBar')||(function(H/*OST*/,S/*ELF*/,I/*NNER*/)
{
H[S] = function ProgressBar(/*str*/title,/*uint*/width,/*uint*/height)
{
(60<=(width||0))||(width=340);
(40<=(height||0))||(height=60);
@grefel
grefel / rmFolder.js
Created March 19, 2016 12:55
Remove Folder recursively
function removeFolder(folder) {
var result = folder.getFiles();
for (var i = result.length -1; i >= 0; i--) {
var fileOrFolder = result[i];
if (fileOrFolder.exists) {
if (fileOrFolder.constructor.name == "Folder") removeFolder(fileOrFolder);
else fileOrFolder.remove();
}
}
folder.remove();
@grefel
grefel / pad.js
Created March 16, 2016 13:33
Pad a number
function pad (number, length, fill) {
if (fill === undefined) fill = "0";
var str = '' + number;
while (str.length < length) {
str = fill + str;
}
return str;
}
@grefel
grefel / findAndDo.jsx
Created January 27, 2016 10:35
GREP Find and do pattern
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
if (app.findChangeGrepOptions.hasOwnProperty ("searchBackwards")) {
app.findChangeGrepOptions.searchBackwards = false;
}
app.findGrepPreferences.findWhat = "";
var findResults = dok.findGrep();
for (var fr = findResults.length-1; fr >= 0; fr--) {
var findTextObject = findResults[fr];
@grefel
grefel / preflight.jsx
Last active January 27, 2016 10:44
Activate Prefilight Profile
preflight(app.documents[0], "pdfCheck");
function preflight(dok, pprofilName) {
var prefligthProfile = app.preflightProfiles.itemByName(pprofilName);
if (!prefligthProfile.isValid) {
var profilePath = new File ("/pathToProfil/pdfCheck.idpp")
if (!profilePath.exists) {
alert("Das Preflight Profil pdfCheck.idpp nicht gefunden");
return;
}
@grefel
grefel / getClipboard.jsx
Created November 18, 2015 15:39
Read clipboard contents with InDesign
try {
var pstwp = app.clipboardPreferences.preferStyledTextWhenPasting;
app.clipboardPreferences.preferStyledTextWhenPasting = false;
var doc = app.documents[0];
var typoQ = doc.textPreferences.typographersQuotes;
doc.textPreferences.typographersQuotes = false;
var tf = doc.textFrames.add();
tf.insertionPoints[-1].select();
app.paste();
@grefel
grefel / wait.js
Last active February 13, 2016 15:41
Wait for Process / Fix InDesign Threading Problems
var oldPreflight = app.activeDocument.preflightOptions.preflightOff;
app.activeDocument.preflightOptions.preflightOff = false;
// wait a maximum of 20 second for the preflight process. Before it runs, all Transactions should be closed.
app.activeDocument.activeProcess.waitForProcess(20);
app.activeDocument.preflightOptions.preflightOff = oldPreflight ;
@grefel
grefel / gist:3025f947c8c916603f27
Created November 18, 2014 10:34
Get String path for an #InDesign Style
var root = app.activeDocument;
var styleString = getStyleString(app.selection[0].appliedObjectStyle);
$.writeln(styleString);
function getStyleString(style) {
var nameArray = [style.name.replace(/:/g, '\\:')];
while (style.parent.constructor.name.indexOf("StyleGroup") > -1) {
style = style.parent;
nameArray.push(style.name.replace(/:/g, '\\:'));
}