Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Insert Note at text cursor

Enthusiast ,
Jan 29, 2018 Jan 29, 2018

Please accept my sincere apologies for the very basic question but I've been a scripting beginner for 20 years and am still struggling.

I would like an InCopy script to insert a Note (containing predetermined text) at the cursor insertion point in text. I thought I would simply adapt the InsertNote.jsx sample supplied with the scripting guide but I don't understand how to get the Note to insert at the text cursor position, rather than at the beginning or end of the story.

Can anyone help me, please? I can't seem to find the answer in the scripting guide in either the Text or Notes chapters.

Thanks,

Alistair

TOPICS
Scripting
1.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

People's Champ , Jan 29, 2018 Jan 29, 2018

Try this:

myNote = app.selection[0].notes.add();

myNote.texts[0].contents = "Hello World!";

This will add a note at the cursor position, and add "Hello World!" to its contents.

Tested in InDesign, but will probably work in InCopy as well.

Whatever is currently selected can be accessed through app.selection[0]. So if you've got a text cursor flashing in the middle of some text, this will return an InsertionPoint. InsertionPoints have a "notes" property, and typically whenever something has a plural pr

...
Translate
People's Champ ,
Jan 29, 2018 Jan 29, 2018

Try this:

myNote = app.selection[0].notes.add();

myNote.texts[0].contents = "Hello World!";

This will add a note at the cursor position, and add "Hello World!" to its contents.

Tested in InDesign, but will probably work in InCopy as well.

Whatever is currently selected can be accessed through app.selection[0]. So if you've got a text cursor flashing in the middle of some text, this will return an InsertionPoint. InsertionPoints have a "notes" property, and typically whenever something has a plural property (textFrames, notes, rectangles), that plural property has an add() method which returns the same object in the singular (textFrame, note, rectangle) which is a single instance of the object.

HTH,

Ariel

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 29, 2018 Jan 29, 2018

Ooh lovely, that did the trick. Thank you ever so much!

Alistair

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 29, 2018 Jan 29, 2018

Hi alidabbs ,

and if you inspect DOM documentation you will see, that also formatted text (also included anchored frames) can be moved or duplicated to an added Note object ( and also out of it ). In fact you do nothing else if you do text.convertToNote() or note.convertToText() .

Regards,
Uwe

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 29, 2018 Jan 29, 2018
LATEST

Thanks, Uwe. The task I had in mind is very basic: I want to allow copy editors to mark/tag any item of queried text as having been investigated already. For example, when a news story gives a person's age or if someone's name has an unusual spelling, they'd like to be able to indicate to the page editors that they have already double-checked those items - in this case by inserting a Note next to the text in question containing a predetermined message such as "Checked" or "OK". A keyboard shortcut assigned to the script would then make it very quick to insert.

Some CMSs provide more versatile ways of doing this by providing multiple check items in a panel. I'd like to demonstrate this basic script first, and if it works I might look into adding alternative check items via a user interface. But that "insertionPoints" detail was throwing me off the scent.

Thanks again,

Alistair

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 29, 2018 Jan 29, 2018

It's easier than you think, although I agree that the example is rather useless. A Note gets added to an insertion point; and an insertion point is every position that you can click a text cursor on.

The text cursor position is always a selection; its length is the length of the selected text and may thus be 0.

This means you only need this short code to add a note at the cursor:

var myNote = app.selection[0].insertionPoints.item(0).notes.add();

//Add text to the note

myNote.texts.item(0).contents = "This is a note.";

You can experiment to see how the "insertion point" code inside a selection works if you select more than one character: the note will always appear at the start of the selection, which is its "item(0)".

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 29, 2018 Jan 29, 2018

Thank you, J, that's absolutely perfect. Very much appreciated.

Alistair

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines