Copy link to clipboard
Copied
Hey there,
I am trying to grab selected text and when running the script it cuts the text and pastes into a new textframe. Here is what I have:
var myDoc = app.activeDocument;
var sel = app.selection[0];
var selectedText = "";
if(app.selection == 0 || sel.characters.length == 0 || !sel.hasOwnProperty("baseline")) {
alert("Please select some text");
exit();
} else {
selectedText = sel.characters.length;
alert(selectedText);
}
I know when I run this I get the count of characters that are selected as a test. not sure how to get the characters into the variable selectedText. would a for loop be what I need?
thanks in advance for any help!
How about the following
selectedText = sel.contents
-Manan
Copy link to clipboard
Copied
Hey there,
I am trying to grab selected text and when running the script it cuts the text and pastes into a new textframe. Here is what I have:
var myDoc = app.activeDocument;
var sel = app.selection[0];
var selectedText = "";
if(app.selection == 0 || sel.characters.length == 0 || !sel.hasOwnProperty("baseline")) {
alert("Please select some text");
exit();
} else {
selectedText = sel.characters.length;
alert(selectedText);
}
I know when I run this I get the count of characters that are selected as a test. not sure how to get the characters into the variable selectedText. would a for loop be what I need?
thanks in advance for any help!
How about the following
selectedText = sel.contents
-Manan
Copy link to clipboard
Copied
How about the following
selectedText = sel.contents
-Manan
Copy link to clipboard
Copied
haha of course. I tried contents, but I must have used it a different way! Thanks for your help!
Copy link to clipboard
Copied
Hi kyleo,
if you selected text your text in your script is stored in variable sel.
You want to move that text to a different text frame? If you like to do this with all its formatting you better use method move() with your selected text and not hunt for the contents of property contents.
// Text is selected.
// A single text frame is positioned on the first spread of your document.
// Move selected text to the first insertion point of that text frame:
app.selection[0].move
(
LocationOptions.AFTER ,
app.documents[0].spreads[0].textFrames[0].insertionPoints[0]
);
Regards,
Uwe Laubender
( ACP )