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

How to create, place, format and paste the clipboard contents into a text frame

New Here ,
Dec 02, 2010 Dec 02, 2010

Copy link to clipboard

Copied

I am new to scripting and need help. I have an existing Indesign document. I need to be able to create a text frame on my current page, the width of my margins with the top of the text frame at the top margin and 1" in height, then format it to be 1-column, and then paste the clipboard contents into it and tag the text with a particular paragraph style. I am using Indesign CS4 on a mac, if that makes any difference. Thanks for any help.

TOPICS
Scripting

Views

1.2K

Translate

Translate

Report

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
Guide ,
Dec 02, 2010 Dec 02, 2010

Copy link to clipboard

Copied

Create a new document with check on "Master Text Frame" in the dialog box. In that dialog box you can enter head margin as well.

Votes

Translate

Translate

Report

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
New Here ,
Dec 02, 2010 Dec 02, 2010

Copy link to clipboard

Copied

Thanks, but what I am needing is a script that I can either assign a shortcut key to or at least just run from the scripting window. It is a repetitive thing that happens hundreds of times in the documents I am working on. There is already text lower down on the page, and I am cutting part of that text and placing and reformatting it at the top of the page, which has been left blank for this purpose.

George

Votes

Translate

Translate

Report

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
Guide ,
Dec 02, 2010 Dec 02, 2010

Copy link to clipboard

Copied

May this will help you. It will create an anchored object with a text what you desired, with object style. You should create an object style before with the x and y co ordinates. You can choose either para style or character style.

var the_document = app.documents.item(0);

// Create a list of paragraph styles

var list_of_paragraph_styles = the_document.paragraphStyles.everyItem().name;

// Create a list of character styles

var list_of_character_styles = the_document.characterStyles.everyItem().name;

// Create a list of object styles

var list_of_object_styles = the_document.objectStyles.everyItem().name;

// Make dialog box for selecting the styles

var the_dialog = app.dialogs.add({name:"Create anchored text frames"});

with(the_dialog.dialogColumns.add()){

with(dialogRows.add()){

staticTexts.add({staticLabel:"Make the anchored frames from ..."});

}

with(dialogRows.add()){

staticTexts.add({staticLabel:"This character style:"});

var find_cstyle = dropdowns.add({stringList:list_of_character_styles, selectedIndex:0});

}

with(dialogRows.add()){

staticTexts.add({staticLabel:"Or this paragraph style:"});

var find_pstyle = dropdowns.add({stringList:list_of_paragraph_styles, selectedIndex:0});

}

with(dialogRows.add()){

staticTexts.add({staticLabel:"Leave one dropdown unchanged!"});

}

dialogRows.add();

with(dialogRows.add()){

staticTexts.add({staticLabel:"Delete matches?"});

var delete_refs = dropdowns.add({stringList:["Yes","No"], selectedIndex:0});

}

dialogRows.add();

with(dialogRows.add()){

staticTexts.add({staticLabel:"Anchored text frame settings:"});

}

with(dialogRows.add()){

staticTexts.add({staticLabel:"Object style:"});

var anchor_style = dropdowns.add({stringList:list_of_object_styles, selectedIndex:0});

}

with(dialogRows.add()){

staticTexts.add({staticLabel:"Frame width:"});

var anchor_width = measurementEditboxes.add({editUnits:MeasurementUnits.MILLIMETERS, editValue:72});

}

with(dialogRows.add()){

staticTexts.add({staticLabel:"Frame height:"});

var anchor_height = measurementEditboxes.add({editUnits:MeasurementUnits.MILLIMETERS, editValue:72});

}

}

the_dialog.show();

// Define the selected styles

var real_find_cstyle = the_document.characterStyles.item(find_cstyle.selectedIndex);

var real_find_pstyle = the_document.paragraphStyles.item(find_pstyle.selectedIndex);

var real_anchor_style = the_document.objectStyles.item(anchor_style.selectedIndex);

// Check if a style is selected

if(find_cstyle.selectedIndex != 0 || find_pstyle.selectedIndex != 0) {

// Define whether to search for character styles or paragraph styles

app.findChangeGrepOptions.includeFootnotes = false;

app.findChangeGrepOptions.includeHiddenLayers = false;

app.findChangeGrepOptions.includeLockedLayersForFind = false;

app.findChangeGrepOptions.includeLockedStoriesForFind = false;

app.findChangeGrepOptions.includeMasterPages = false;

if(find_cstyle.selectedIndex != 0) {

app.findGrepPreferences = NothingEnum.nothing;

app.findGrepPreferences.appliedCharacterStyle = real_find_cstyle;

} else {

app.findGrepPreferences = NothingEnum.nothing;

app.findGrepPreferences.appliedParagraphStyle = real_find_pstyle;

app.findGrepPreferences.findWhat = "^";

}

// Search the document

var found_items = the_document.findGrep();

myCounter = found_items.length-1;

do {

// Select and copy the found text

var current_item = found_items[myCounter];

if(find_pstyle.selectedIndex != 0) {

var found_text = current_item.paragraphs.firstItem();

var insertion_character = (found_text.characters.lastItem().index) + 1;

var check_insertion_character = insertion_character + 1;

var alt_insertion_character = (found_text.characters.firstItem().index) - 1;

var the_story = found_text.parentStory;

app.selection = found_text;

if(delete_refs.selectedIndex == 0) {

app.cut();

} else {

app.copy();

}

} else {

var found_text = current_item;

var insertion_character = (found_text.characters.lastItem().index) + 2;

var check_insertion_character = insertion_character;

var alt_insertion_character = (found_text.characters.firstItem().index) - 1;

var the_story = found_text.parentStory;

app.selection = found_text;

if(delete_refs.selectedIndex == 0) {

app.cut();

} else {

app.copy();

}

}

// Make text frame from selection

try {

app.selection = the_story.insertionPoints[check_insertion_character];

app.selection = the_story.insertionPoints[insertion_character];

} catch(err) {

app.selection = the_story.insertionPoints[alt_insertion_character];

}

var the_anchored_frame = app.selection[0].textFrames.add({geometricBounds:["0","0",anchor_height.editContents,anchor_width.editContents],anchoredObjectSettings:{anchoredPosition: AnchorPosition.ANCHORED}});

app.selection = the_anchored_frame.insertionPoints[0];

app.paste();

// Apply the object style now to "force apply" paragraph style set in the object style

if(anchor_style.selectedIndex != 0) {

the_anchored_frame.appliedObjectStyle = real_anchor_style;

}

myCounter--;

} while (myCounter >= 0);

} else {

alert("No styles selected!");

}

Votes

Translate

Translate

Report

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
Guide ,
Dec 02, 2010 Dec 02, 2010

Copy link to clipboard

Copied

Just copy the script and run. May be this is what you need!!!

Votes

Translate

Translate

Report

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
New Here ,
Dec 06, 2010 Dec 06, 2010

Copy link to clipboard

Copied

LATEST

Thanks, but you are way too far ahead of me. Just so I can learn, can we take things one step at a time? I've been mostly looking at applescript tutorials, and found one that supposedly does exactly what my first step needs to be (http://www.mactech.com/articles/mactech/Vol.22/22.11/2211AppleScript/index.html):

This is the way it reads in the tutorial:

tell application "Adobe InDesign CS2"
   tell page 1 of document 1
      make new text frame with properties {geometric bounds:{1, 1, 3, 6}}
   end tell
end tell

However, when I modify it to fit my circumstance, I get an error message. My script is:

tell application "Adobe InDesign CS4"
    --create text frame at top of active page in active document
    tell active page of active document
        make text frame with properties {geometric bounds:{1, 1, 2, 7.75}}
    end tell
end tell

When I run the script, it goes to the "make..." line and then returns the error:

make with properties {geometric bounds:{1, 1, 2, 7.75}} new text frame
        --> error number -1708
Result:
error "Adobe InDesign CS4 got an error: Can’t make class text frame." number -2710 from text frame to class

I can't figure out why.

George

Votes

Translate

Translate

Report

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