Forum Replies Created
-
AuthorPosts
-
Theunis De Jong
MemberKelli, I’m afraid that won’t work. In the current setup, the original value gets overwritten once, and then you would have lost its original value for the next time.
Since you mention multiple years (I was basically thinking you’d need only one), I’m thinking a more complicated set-up would still be possible. Something like:
1. you create a variable “year” and set its contents to your starting year;
2. on opening the document, the script creates a *new* variable named “year-now” and sets its value to “now minus variable value”. You would use *this* variable in your document, not the original “year” one;
3. .. and on saving and then re-opening this document, the variable “year-now” would get updated but “year” would stay the same.If you need to be able to manually add more variables, I can think of two further scenario’s. Either you could add each one to the script (requiring a restart each time you modify it), or devise a consistent naming scheme where a set prefix determines whether the new variable should be created. Such a prefix could be something like year-” and so, when you add a new variable “year-DavidB”, the script checks all variables starting with “year-” and creates “now-DavidB”. (It cannot create “year-DavidB-now”, because a next time it would create one called “year-DavidB-now-now” … and so on … see the problem? :)
If on of these workflows would work for you, I could look into it. Other script writers are hereby invited to think along :)
Theunis De Jong
MemberIndeed GREP is thinking in the wrong direction. GREP is nothing more than a (very) fancy search-and-replace function.
That said: the functionality you are looking for – math calculations – can be done inside InDesign through a script! A script has access to the Text Variables in your current document (https://helpx.adobe.com/indesign/using/text-variables.html) and so it can change their contents. And JavaScript (my preferred InDesign scripting language) has built-in operators to retrieve the current date.
If you write the above down in a basic script, you’ll practically have what you ask for; but then the problem is when to run this script. After all, if you cannot remember to change a year value once a year, you’d also be prone to forgetting to run the script at least once a year (“at least once”, because once run, it’d set the variable to the correct value for the entire year to come).
It’s far easier if your friendly InDesign kept the variable up-to-date. And it can! Here, copy this rather short-but-sweet script into the Extendscript Toolkit Editor and save it as a new file “set_experience_variable.jsx” in a folder called “Startup Scripts” – not your regular “Scripts Panel” folder. In case this is new for you, see “Download the script” in https://creativepro.com/add-missing-options-to-the-book-menu.php for a practical step-by-step instruction. (But no need to download that script.)
//DESCRIPTION:Write date difference in variable
// A Jongware Script 12-Jul-2019
#targetengine "set_experience_variable"app.addEventListener("afterOpen", check_and_set_variable, false);
function check_and_set_variable (event)
{
var theDoc = event.parent;
if (theDoc instanceof Document)
{
var tvar = theDoc.textVariables.item('experience');
if (tvar.isValid && tvar.variableType == VariableTypes.CUSTOM_TEXT_TYPE)
{
tvar.variableOptions.contents = String(new Date().getFullYear() - 1976)
}
}
}For the script to work at start-up, you must quit and restart InDesign once you copied this into the Startup Scripts folder, but afterwards it should fire automatically. What it does is, every time you OPEN an existing document, it checks if there is a Text Variable called “experience” in that document. If it is, it double-checks if its type is “Custom Text” (so it can change the contents), and if that is the case, it immediately sets the contents string to your difference in years.
You can see it works correctly: 1. Create a new document (or open an existing one). 2. Create a new Text Variable of type “Custom Text” and name it “experience”. Set its contents to some random text such as “oooh so clever”. 3. Insert this text variable somewhere in an appropriate place in the document text. For now, it’ll read “I have ooh so clever years of experience”. 4. Save and close the document. 5. The magic happens when opening this document again – please do so now!
If you followed all the steps above correctly, the text will now magically read “I have 43 years of experience”. And it will automatically update each new year!
Theunis De Jong
MemberRobert, it really sounds to me that InDesign is not the right writing tool for you. You are looking for “a two-step source/citation capability” – that sounds like a full-fledged reference list. InDesign’s Endnotes are just that: a simple numbered list, where each consecutive number in the text points to a single note at the end of that text. Exactly like footnotes, except for, well, footnotes go at the bottom of a page but endnotes go at the end of a chapter (or section, or book). Just like footnotes, you cannot have them out-of-order, have multiple references to the same ‘note, or have your notes sorted on last names but still point to the correct note number.
As you already found out, Microsoft Word does not do this out-of-the-box either. For Word, there are multiple cross-reference managers available; for InDesign I know of none. (Also not for nothing. ID is generally not considered a good writing tool!)
Theunis De Jong
MemberOh that is a nice catch! I’ve only used the most basic form of parameters, nothing really fancy, and this is really something to keep in mind. Kasyan’s summary is extremely helpful, describing this problem (oversight? bug?).
Well done on going all the way pursuing a solution!
Theunis De Jong
MemberHi José!
Thanks for your support for Python! I don’t have many opportunities to use it, but every time I do, I think “oh but this is much easier than ExtendScript :) I indeed stay away from the ESTK as far as possible .. At work – Windows – I use TextPad, at home – Mac – I really like the ol’ TextWrangler (nearing its end-of-life support, alas). On both systems I also use Sublime Text, which – you might be interested in this! – natively can run Python!
As for your problem … hm. I did not think there was any limit, but then again I might be mistaken and you just ran into it. You can try to minimize the number of Undo’s by wrapping only some of your functions inside an Undo. The Undo does not really *have* to be all around the entire script, it can be used for any single function as well.
Theunis De Jong
MemberI am not aware of any changes in the Undo functionality, but then again, maybe you found a bug.
There “should” not be a limit to the number of actions, but — well, maybe there is some kind of limit after all. Can you test if Undo works as expected with a smaller script? Or with less than your 100 actions?
Theunis De Jong
MemberHere is a useful variant: save this single line as “apply-YourStyle.jsx” and it will apply the style “YourStyle”. Save it as “apply-somethingElse.jsx” and it will apply “somethingElse” – the name of the style gets taken from the script name! So you can copy the script as many times as you like, and you only have to change its file name.
app.selection[0].applyParagraphStyle(app.documents[0].paragraphStyles.itemByName(app.activeScript.name.match(/apply-(.+)\.jsx?/)[1].replace(/%20/g, ' ')));Do note, however, that this only works with very basic style names, containing simple filename characters only. That is, you cannot make it work with an overly fancy style name such as “Header 1 + line above (when not at top of page)”, nor does it work with Style Groups. Having spaces in the style name should be okay, though.
May 1, 2019 at 3:30 am in reply to: Changing the paragraph style of the NEXT paragraph using Find or GREP #116306Theunis De Jong
MemberThe prettifying software of this forum automatically changed straight single and double quotes to “correct” curly opening and closing. And JavaScript cannot handle that! There is a minimal hint to this if you copied the code into Adobe’s own ExtendScript Toolkit Editor, or another code editor that does syntax-coloring: you can see text strings get a different color when you use the ‘correct’ type of quotes.
Trying again below; if it doesn’t work, delete the quotes one by one and replace them with *correct* correct straight ones.
app.findTextPreferences = null; app.findTextPreferences.appliedParagraphStyle = "H2"; var myResults = app.activeDocument.findText(); for (i=0; i<myResults.length; i++) myResults[i].parentStory.paragraphs.nextItem(myResults[i].paragraphs[0]).appliedParagraphStyle = "No Indent Body";
Theunis De Jong
MemberYes, see https://creativepro.com/exporting-all-stories-text-rtf.php
Admittedly, the article is from August 5, 2008, but don’t let that deter you. As the British say, plus ça change, plus c’est la même chose – there have been no significant changes and/or improvements in this, the past decade.
Theunis De Jong
MemberQuite surprising: the official code
SpecialCharacters.FOOTNOTE_SYMBOLdoes not insert anything at all! “Undo” also says “Undo Insert Text” as if something was inserted. But there is nothing there.Other codes such as
SpecialCharacters.AUTO_PAGE_NUMBERandSpecialCharacters.TRADEMARK_SYMBOL*do* work as expected.January 23, 2019 at 3:40 am in reply to: Export InDesign File both as spreads and single pages at the same time? #113820Theunis De Jong
MemberBut then your client would have two separate PDF files!
You can also send them some basic instructions. The Adobe Acrobat Reader allows changing the view to Single page and to Double page. If you want to start the double-page view with a single odd page, set “Two up (Cover page)” as the default view option; then, a reader can still change it to “Single page” if he wants.
Theunis De Jong
MemberThat is specific enough to not exist anywhere. No sweat, though. Fortunately it is small enough and quick to write.
Select any of your threaded frames, and run this script. Be warned that it exactly does what it says on the tin: it blandly and blindly converts the text inside each frame to a single hyperlink by pasting “https://” in front of it and then connects that one link to its parent text frame. I have no idea what happens if there already is a link connected to the frame, or if you (accidentally or otherwise) have more text than a single link inside a text frame. Feel free to experiment, though :)
tc = app.selection[0].parentStory.textContainers; for (f=0; f<tc.length; f++) { src = app.activeDocument.hyperlinkPageItemSources.add(tc[f]); dest = app.activeDocument.hyperlinkURLDestinations.add('https://'+tc[f].contents.replace(/+$/, '')); app.activeDocument.hyperlinks.add(src, dest); }Theunis De Jong
MemberCould it be a User Error instead?
We see this a lot at our office: people marking text with strikeout — so, a “delete” request — and use the comment field to type in what text it should be ‘replaced’ with.
To mark text for replacement, use the Replace Text With marker.
October 25, 2018 at 4:14 am in reply to: Replacing certain alternate glyphs in a font by default #111144Theunis De Jong
MemberAlready under discussion on https://forums.adobe.com/thread/2552042
(Please avoid cross-site duplicate discussions as it only leads to fragmented information.)
Theunis De Jong
Member“Spam removal in isle #3 please.”
-
AuthorPosts
