Copy link to clipboard
Copied
Looking for a Grep command or script that will alternate the baseline shift of every other letter in a paragraph or sentence. This is for a childrens book lettering?
Just send you a PM…
Copy link to clipboard
Copied
Copy link to clipboard
Copied
that is extremely helpful how do it edit it ? with brackets
Copy link to clipboard
Copied
download is not available?
Copy link to clipboard
Copied
Follow the link, scroll to the bottom of page, right-click on Random_Letter_Presser.jsx, choose Save Link As…
Install the script, run it. Here's a panel window you should see:
Copy link to clipboard
Copied
failed no file?
Copy link to clipboard
Copied
You can find the script in this link:
https://github.com/GitBruno/Novelty/tree/master/Scripts
I had problems accessing the link in Safari, but had no problems with Chrome or Edge.
Copy link to clipboard
Copied
even better
Copy link to clipboard
Copied
Does this work with CC2018? seems to not
Copy link to clipboard
Copied
OK. Just copy/paste (carefully!) the code below. Warning: script works pretty slowly, test on a small amount of text first.
Tested in CC2019, works just fine.
/*
Letter_Presser.jsx
Version 0.2 (TEST)
Experimental InDesign CS5 JavaScript
Bruno Herfst 2011
This script sets a randome baselineshift between two values
to all text found in seleced paragraph style
can also set random thin outlines for extra letter-press feel.
*/
#target "InDesign"
//global varialbles
var ps, cw, bls, sw;
main();
//============================================== FUNCTIONS =====================================================
function main(){
var myDoc = app.documents.item(0);
// Create a list of paragraph styles
var list_of_All_paragraph_styles = myDoc.paragraphStyles.everyItem().name;
list_of_All_paragraph_styles.unshift("All paragraph styles");
// Make the dialog box for selecting the paragraph styles
var dlg = app.dialogs.add({name:"LetterPresser"});
with(dlg.dialogColumns.add()){
with(dialogRows.add()){
staticTexts.add({staticLabel:"Do"});
with(myFitButtons = radiobuttonGroups.add()){
var c = radiobuttonControls.add( { staticLabel : 'Characters', checkedState : true } ),
w = radiobuttonControls.add( { staticLabel : 'Words' } );
}
staticTexts.add({staticLabel:" in paragraph style:"});
var find_paragraph = dropdowns.add({stringList:list_of_All_paragraph_styles, selectedIndex:list_of_All_paragraph_styles.length-1});
}
with(dialogRows.add()){
with(borderPanels.add()){
staticTexts.add({staticLabel:"Max baselineshift:"});
bls = 0.225;
var myBlsField = measurementEditboxes.add({editUnits: MeasurementUnits.POINTS,editValue:bls});
staticTexts.add({staticLabel:"Max strokewidth:"});
sw = 0.15;
var mySwField = measurementEditboxes.add({editUnits:MeasurementUnits.POINTS,editValue:sw});
}
}
with(dialogRows.add()){
with(dialogColumns.add()){
}
}
}
//show dialog
if(dlg.show() == true){
//get dialog data
sw = mySwField.editValue,
bls = myBlsField.editValue,
cw = c.checkedState; // true: character, false: word
if (find_paragraph.selectedIndex == 0) {
ps = false;
} else {
ps = myDoc.paragraphStyles.item(find_paragraph.selectedIndex-1);
}
// Set find grep preferences to find all paragraphs with the selected paragraph style
app.findChangeGrepOptions.includeFootnotes = false;
app.findChangeGrepOptions.includeHiddenLayers = false;
app.findChangeGrepOptions.includeLockedLayersForFind = false;
app.findChangeGrepOptions.includeLockedStoriesForFind = false;
app.findChangeGrepOptions.includeMasterPages = false;
app.findGrepPreferences = NothingEnum.nothing;
if(ps == false){
app.findGrepPreferences.appliedParagraphStyle = NothingEnum.nothing;
} else {
app.findGrepPreferences.appliedParagraphStyle = ps;
}
app.findGrepPreferences.findWhat = "^.+";
//Now let’s find the paragraphs
//Search the current story
var found_paragraphs = myDoc.findGrep();
var myCounter = 0;
var myMessage = false;
do {
try {
// Create an object reference to the found paragraph and the next
wavePara(found_paragraphs[myCounter]);
myCounter++;
} catch(err) {
myMessage = err;
myMessage = "Couldn't find anything!";
}
} while (myCounter < found_paragraphs.length);
if(myMessage == false){
var myMessage = "Done setting "+(myCounter)+" paragraphs!";
}
alert(myMessage);
//the end
dlg.destroy();
} else {
//cancel
}
}
//-------------------------------------------------------------------------------------------------------------
function wavePara(myPara){
myPara.strokeAlignment = TextStrokeAlign.CENTER_ALIGNMENT;
var myLines = myPara.lines;
//for lines in paragraph
for (var line=0, ll=myLines.length; line < ll; line++){
var myLine = myPara.lines[line];
var cl = myLine.characters.length;
var mod = 0;
startValue = sw;
//for characters in lines
for (var character=0; character < cl; character++){
try{
var myCharacter = myLine.characters[character];
myCharacter.strokeColor = "Black";
myCharacter.baselineShift = randomInRange(0,bls);
myCharacter.strokeWeight = randomInRange(0,sw);
}catch(r){
//alert(r.description);
//This should not happen but if it does deal with it quitely
line-=1; // redo line
ll+=1; // in case the paragraph got longer
// if not will break anyway
break;
}
}
}
}
//-------------------------------------------------------------------------------------------------------------
function randomInRange(start,end){
return Math.random() * (end - start) + start;
}
Copy link to clipboard
Copied
New to scripting do i paste into brackets and save as a .jsx
Copy link to clipboard
Copied
Im obviously doing something wrong
i drop the script in the script panel in CC2019 ( at home now(
click on the sentence and hit run script
Copy link to clipboard
Copied
I'm moving this discussion to the InDesign Scripting forum.
Copy link to clipboard
Copied
FWIW, a newer version (1.4, post #6) offers more settings and, likely, optimized code (works a bit faster):
The author didn't invest much in UI, though
Copy link to clipboard
Copied
where is the newer version ?
Copy link to clipboard
Copied
can you email me the script? and step by step? I know how to install it but how do I use it on a paragraph?
Copy link to clipboard
Copied
Just send you a PM…
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Works just fine in Win7/CS6, and Win10/CC2019. Here's a screenshot from CC2019, v14.02, with default script settings already applied to the first paragraph.
Could your problem be a Mac related? Maybe someone on Mac machine will chime in to verify.
Copy link to clipboard
Copied
Im running Mac 10.16.6 High Seirra on a Mac Book Pro with CC2018/2019?
Copy link to clipboard
Copied
thank you winterm all I needed was a good reeboot!
Copy link to clipboard
Copied
New to scripting ...
copy / paste the code into plain text editor (like Notepad on Windows). There must be no formatting, just plain text!
Change file extension from txt to jsx.
here's how to install:
https://indesignsecrets.com/how-to-install-scripts-in-indesign.php
do i paste into brackets
not sure what do you mean
Copy link to clipboard
Copied
Hi winterm ,
I guess AmybethMenendez means this:
Brackets Blog - The Free, Open Source Code Editor for the Web
Regards,
Uwe
Copy link to clipboard
Copied
Oh, very likely. However, anything more than a plain text editor is a bit overkill in this case.