Copy link to clipboard
Copied
I want to use two shortcuts to improve my work.
I think it is possible by scripting but i don't know how so i ask here.
i want to create a shortcut to increase space after paraprgaph as the button in palette and one to increase the space before the paragraph.
my left mouse button and relative finger will thank you forever.
1 Correct answer
For many years I have used small scripts to add or remove space before or after paragraphs. That's much easier than creating separate paragraph styles.
Two scripts below: the first adds 1 pt to the space before the currently selected paragraph, the second one adds half a line of white before the current paragraph. 'Selected' means: just click somewhere in the paragraph.
I use slight variants of these script to decrease the space by 1 point (simple change += with -=), and to add/remove space
...Copy link to clipboard
Copied
I don't know anything about scripting but why don't you simply use paragraph styles?
Copy link to clipboard
Copied
For many years I have used small scripts to add or remove space before or after paragraphs. That's much easier than creating separate paragraph styles.
Two scripts below: the first adds 1 pt to the space before the currently selected paragraph, the second one adds half a line of white before the current paragraph. 'Selected' means: just click somewhere in the paragraph.
I use slight variants of these script to decrease the space by 1 point (simple change += with -=), and to add/remove space after the selected paragraph (simply replace spaceBefore with spaceAfter).
Then assign these scripts to keyboard shortcuts. On my keyboard I use these keys:
F1: add 1 pt space before
Shift+F1: add half a line of white before
Ctrl+F1: remove 1 pt space before
F2: add 1 pt space after
Shift+F2: add half a line of white after
Ctrl+F2: remove 1 pt space after
These very simple scripts have saved me an enormous amount of time over the years.
P.
// Add 1 pt space before (to add e.g. 1 mm, use '1mm')
try {
app.selection[0].spaceBefore += 1;
} catch (e) {
alert (e.message);
}
// Add half a line of white before
function leading (p) {
if (p.leading == Leading.AUTO) {
return (app.selection[0].pointSize * p.autoLeading) / 100;
}
return p.leading;
}
try {
par.spaceBefore += leading (par) / 2;
} catch (e) {
alert (e.message);
}
Copy link to clipboard
Copied
Mr Peter Kahrel, You are a lifesaver!
Copy link to clipboard
Copied
Mr. Kahrel, thank you for this amazing script. It is wonderful! How useful !!!
And adding, as you suggest, a keyboard shortcut to run it, is the perfect solution I was looking for.
Thanks!
Copy link to clipboard
Copied
I agree, this is very useful Peter! Way to solve what I see as an oversight by the InDesign team. I have packaged the scripts as rtf files (this msg board doesn't support posting .jsx). So change the suffix to .jsx and put into the 'Scripts Panel' folder... they should probably be a part of any power users install.
Copy link to clipboard
Copied
Thanks, David. In the meantime I put the scripts on CreativePro's website:
https://creativepro.com/files/kahrel/indesign/fine-tune-paragraph-spacing.html
Copy link to clipboard
Copied
Super helpful, as I have to basealign everything for a publisher client.
I see the scripts on CPro lead with "app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS".
When I first ran it, it added 1p, since my default unit was 1p. I changed my default unit to Points, and now it works. It doesn't work for me to do this as noted above:
(to add e.g. 1 mm, use '1mm')
I tried putting 1pt in the script and it errored on the pt.
If I select a range of paragraphs, it doesn't apply to all, just the one where the cursor is. A range would be nice.
What I'd really love to do is search the selection for a specific paragraph style and increment only that style. My text alternates like H1, P, H1, P, and I can only add space above the H1s. I know I could search the H1s and change to a different style, like H1+p1, but that's impractical for many reasons.
Scripts and GREP are always a lifesaver!
Copy link to clipboard
Copied
If your styles are all base-aligned, why would you use this override tweaking at all?
┋┊ InDesign to Kindle (& EPUB): A Professional Guide, v3.1 ┊ (Amazon) ┊┋
Copy link to clipboard
Copied
Hi James,
Not sure I understand your question... my styles do not result in base-align automatically, unfortunately. I have to tweak every page to hit the base-align (both columns and spreads) and that means addeing equal space above, say, all 5 H1s in a column to try to hit base-align. This is hard with the intervening paragraphs.
Copy link to clipboard
Copied
Perhaps I'm misreading this topic. I meant enabling a baseline grid, then mapping the styles to align to it. With that setup, there's no need to micro-tweak spacing to 'hit the baseline' (which I take to mean the bottom margin).
I'm just not a fan of "fixing on the fly" for long layout, but few of my projects are "one and done"; I need them to be stable for future revisions and editions. (I'm even less a fan of local-override tweaking, for that and more general reasons.)
┋┊ InDesign to Kindle (& EPUB): A Professional Guide, v3.1 ┊ (Amazon) ┊┋
Copy link to clipboard
Copied
I don't have that option, since I am not the publisher/designer. If I were starting from scratch and creating book specs for my client, yes, I would design my styles that way. This is what my client requires, unfortunately. They have detailed specs for above and below all styles, then tell me to override them all on a page by page basis to base-align the pages. It's not wise, for sure, but I am the production grunt here, not the one setting the specs. This is freelance book production life, and I believe even the famous Peter Kahrel experiences this, as his great script suggests. 🙂
Copy link to clipboard
Copied
All understood. I usually have the luxury of controlling production specs and tend to pass on ones where such things are dictated to me against best professional judgment. 🙂
┋┊ InDesign to Kindle (& EPUB): A Professional Guide, v3.1 ┊ (Amazon) ┊┋
Copy link to clipboard
Copied
I could be wrong, but I think James might be suggesting a use of baseline-grid, (and possibly object-styles) which might more effectively solve things in an automated manner. But of couse, I have no idea as to the exact challenges you might be facing in the layout/pieces that might prohibit that.
Copy link to clipboard
Copied
Thankyou so much sir, this script save many time.
Copy link to clipboard
Copied
I am using this:
https://youtu.be/P28LMcaRspk?si=De_UkMb1v8NFGloy
Can be adapt for paragraphs spacing, or combined with script what was posted here.
Amazing useful btw 🙂
Copy link to clipboard
Copied
That is an interesting video. I don't really need anything but what I said above, adding 1pt or 2pt to selected paragraphs, but ideally exclusive by style. That's a lot to control, I realize. And I'm on a Mac, which makes so many things more difficult. I would probably prefer to use a keyboard shortcut instead of mouse wheel, but it does sound interesting.
Copy link to clipboard
Copied
The script you mentioned was designed for a purpose. What you're after is to balance certain headings so that the baseline of the text frame's last line is on the frame's bottom. For that, too, I used a script. Here it is.
You specify the paragraph style names to target in the second line of the script.
To use the script, select the text frame and run the script. It determines the space between the bottom of the text frame and the last line's baseline, divides it by the number of headings on the page, and adds that to each paragraph's space-before. If a heading is at the top of the page it's ignored (because setting spaceBefore on the frame's first paragraph has no effect).
(function () {
var headingStyles = ['SecA', 'SecB', 'SecC'];
function findHeadings (p) {
var a = [];
var re = new RegExp ('^(' + headingStyles.join('|') + ')$');
for (var i = p.length-1; i >= 0; i--) {
if (p[i] != app.selection[0].paragraphs[0]
&& re.test (p[i].appliedParagraphStyle.name)) {
a.push (p[i]);
}
}
return a;
}
if (app.selection.length === 0
|| !(app.selection[0] instanceof TextFrame)) {
exit();
}
var headings = findHeadings (app.selection[0].paragraphs.everyItem().getElements());
if (headings.length === 0) {
exit();
}
var gap = app.selection[0].geometricBounds[2]
- app.selection[0].lines[-1].baseline;
var delta = gap / headings.length;
for (var i = 0; i < headings.length; i++) {
headings[i].spaceBefore += delta;
}
}());
Copy link to clipboard
Copied
Thanks, Peter! That's very interesting. It may motivate me to re-do some documents with two separate text frames for columns, so I can run it separately for each column. I look forward to further experimentation with this.
Best Regards,
Carol
Copy link to clipboard
Copied
I'm late to the party and maybe I'm also missing the point - but TextFrame can be justified vertically...
Copy link to clipboard
Copied
Vertically justifying a text frame is almost always problematic. You can't specify where the space should be added; it often adds leading, which is a mortal sin; and it usually slows down InDesign.
Copy link to clipboard
Copied
Indeed, @Robert at ID-Tasker , that is so indiscriminate, the text would be a mess.
"My text alternates like H1, P, H1, P, and I can only add space above the H1s."
Client has very strict rules about where space above is allowed.
Copy link to clipboard
Copied
That's why I've started my sentence from "I'm late to the party and maybe I'm also missing the point "...
In some circumstances it wouldn't be a problem - in your situation - it won't work.
Copy link to clipboard
Copied
Hold your horses, Carol. The script is very easy to change so that it targets a column rather than the whole frame.
Copy link to clipboard
Copied
@Peter Kahrel , that's excellent to hear. I have homework to do.


-
- 1
- 2