Applescript - replace text in specific text frame
Throwing another one out there to is excellent forum:
I know how to change text in a document:
tell application "Adobe InDesign CS5.5"
set find text preferences to nothing
set change text preferences to nothing
--Search the document for the string.
set find what of find text preferences to "SigBelowT"
--Replace the search with what we pulled from the db
set change to of change text preferences to theSigCopyB
-- this is the actual search and replace command
set myFoundItems to change text
end tell
I'm trying to change text only in a specific paragraph, named as a layer in my source inDesign Document:
tell application "Adobe InDesign CS5.5"
tell the active document
try
set find text preferences to nothing
set change text preferences to nothing
set Text_Frame to the text frame "PH"
set find what of find text preferences to "~" of text frame Text_Frame
set change to of change text preferences to " "
set myFoundItems to change text
end try
end tell
end tell
I've tried several iterations similiar to this one, but I'm not hitting the right combination.
Suggestions??
headed down this path:
tell application "Adobe InDesign CS5.5"
try
set myDoc to active document
set Text_Frame to the text frame "PH"
set find text preferences to nothing
set change text preferences to nothing
set find what of find text preferences to "~"
set change to of change text preferences to " "
tell myDoc
tell Text_Frame
set myFoundItems to change text
end tell
end tell
end try
end tell
still not working
Similar Messages
-
Applescript replace text with clipboard
Sorry if this has been asked before, I have been searching for hours and cannot find anything.
what I would like to do is copy text from a safari webpage , swap to the textedit program and replace text with the copied contents.
for eg.
from safari I have copied the user link, I then want it to swap over to textedit, find the keyword "userlink" and replace it with the copied content from safari
userlink
email
number
HHopefully I have explained it correctly, and thanks in advance for any helpHi,
Like this:
set x to the clipboard as «class RTF »
tell application "TextEdit"
set first word of front document whose it = "userlink" to x
end tell
If you want plain text, remove as
as «class RTF » -
Applescript: open Pages doc from Templete, change filename and replace text
Hi!
I just got started with applescript and i want a script that does the following:
1. open "choose from list" dialog to choose the topic of my document
from 4 possibilities (here for example A, B, C, D)
2. open document from TemplateXY
3. set document name with date and topic (dd.mm.yyy) "16.02.2011 - A"
4.inside of document: replace text "date" with the currend date (dd.mm.yyy)
and the text "topic" with the topic chosen in (1.) "A"
this is what i already did:
here as colored screenshot:
http://i55.tinypic.com/2mnhxkm.jpg
set datum to do shell script "date \"+%d.%m.%Y\""
--choose topic:
set chosentopic to choose from list {"A", "B", "C", "D"}
--text "topic" becomes replaced throug variable topic
set searchstringT to "topic"
set replacestringT to chosentopic
--text "date" gets replaced by currend date (variable datum)
set searchstringD to "date"
set replacestringD to datum
--open pages, define filename & do search&replace of the strings defined above
tell application "Pages"
activate
set DocName to datum & " - " & chosentopic
set (every text where it is searchstringT) to replacestringT
set (every text where it is searchstringD) to replacestringD
end tell
the "choose from list" dialog works and the variables like topic, datum and the search&replace strings get defined as well
my problems are:
i only get an error that the text could not be replaced
i dont know how to get a new document from a template and how to get its filename changed
i really just started doin things with applescript for a day so i hope you can help me
regards
DaNylz
Message was edited by: DaNylzTry something like this:
set myFoundItems to change text text of all page items of pages 3 thru 5 of document 1
Shane Stanley <[email protected]>
AppleScript Pro Sessions <http://scriptingmatters.com/aspro> -
How to enable the script label of a text frames in indesign using applescript
hi all,
am using Indesign CS2 with applescript..
Using script I have to open a template in indesign and flow the word document into it...
I can able to flow the word document into the template using "Place" command..but script labels of the text frames gets disabled...
I need the script labels to be enabled...
can anybody help me
thanks in advanceScript labels can't be disabled, so I'm not sure what your problem is -- perhaps seeing some code could help. Could it be that you're referencing a page item by label, but it is not responding because the item is part of a group?
Shane Stanley <[email protected]>
AppleScript Pro Sessions <http://scriptingmatters.com/aspro> -
Replace text with image using Applescript in InDesign CS5
Hi to everyone, i'm looking for some suggestions to resolve my problem.
I've to replace some strings with jpeg images stored on my pc
Here is the code to replace two strings with the new ones.
tell application "Adobe InDesign CS5"
set myDocument to active document
set myPage to page 1 of myDocument
set stringsToReplace to {"111", "222"}
repeat with iterator from 1 to (count stringsToReplace)
set find text preferences to nothing
set change text preferences to nothing
set myFoundItems to nothing
set element to item iterator of stringsToReplace
if element is "111" then
set find what of find text preferences to "111"
set change to of change text preferences to "ONE"
set myFoundItems to change text
display dialog ("Found : " & (count myFoundItems) & " occurences of " & element)
else if element is "222" then
set find what of find text preferences to "222"
set change to of change text preferences to "TWO"
set myFoundItems to change text
display dialog ("Found : " & (count myFoundItems) & " occurences of " & element)
end if
end repeat
set find text preferences to nothing
set change text preferences to nothing
end tell
Can you hel me?
Thanks in advance.Hello, I have a couple of questions for you… How come you have strings in text frames… Would you not be better off using labels for this…? ( thats how I would do this ). Off the top of my head I think you will need to remove any text content from the frame to be able to change it's content type… only then will you be able to place a graphic… How are you associating your strings with the required image files… Do you have this in some extenal file Excel or FMP.
-
I'm doing a multiple record data merge, I have 2 frames both with variable data placed inside.
I would like to specify that one of the text frames only merges once(first record) and the other frame multiple times for each record in the data file.
Is it possible?
I thought that perhaps if I place the text frame that must merge once on the master page, it would work. But you are not allowed to place variable text on the master and on the document page.
I'm going to try it through scripting next, but thought that perhaps there is an easier way that I'm not aware of.
Thanks,
SuzanneSuzanne,
If you were trying to post a screen shot, you would need to return to the forum and post it using the "camera" icon at the top of the post editing windows.
I use a plug-in from Em Software called InData. One of the benefits for what I do is there are no individual frames on a page to deal with post-merge. Individual frames are great for simple merges (address labels, post cards, etc.). But I typically do more other types of merges.
That said, there is a drawback--one needs to come to an understanding of writing expressions that actually parse the incoming data. So in the spice price list example, that looks like:
It's reasonably easy once one does it a few times. And it can be far more complicated. The above is from Em Software's samples that has been tweaked. The best thing I can recommend would be to download the trial and see for yourself. They are good at responding to specific questions if you get stumped.
I imagine this all could be scripted somehow in ID. But I have no idea how and the plug-in just lets me keep working.
Mike -
Add xml tag to specific words in a text frame
Dear all,
I'm pretty sure this can't be too much of a hassle, but after hours of experimenting, searching and reading I can't seem to look at it from the right angle. I'm trying to find a way to search for a specific word ('Figure', in my case) in a given text frame, and add a corresponding XML tag to it automatically. I've found plenty of information on how to apply it to a page item as a whole, but from there no approach seems to work. Seeing as I'm fairly new to InDesign scripting, any nudge in the right direction would be an immense help.
Kind regards and thanks in advance,
JulianHi Julian,
Is this you asking?
var doc = app.activeDocument;
app.findTextPreferences.findWhat = "figure";
var found = doc.findText();
for(var i =0;i<found.length;i++)
doc.xmlElements[0].xmlElements.add({markupTag:"figure", xmlContent:found[i]});
Regards,
Chinna -
Replace text in applescript with applescript.
I'm trying to start a script that changes part of another script as it needs to alter slightly each day,
I need to replace this line of the script that I am holding in the resources (so never changes)
choose from list ItemTypesList with prompt "Choose Item" default items {"ER"}
I need to change the part that is ER to the ItemType
choose from list ItemTypesList with prompt "Choose Item" default items {"ItemType"}
Then save in a different location with overwriting?
I managed to get so far but having difficulty get it to find and replace and then save.
the find and replace is borrowed from another script I found (but for text editor)
Many Thanks
Matt
set theScript to (path to me)'s POSIX path & "Contents/Resources/EverythingCropProcess.scpt"
set saveScript to (path to home folder)'s POSIX path & "Workflow/EverythingCropProcess.scpt"
log theScript
set ItemTypesList to {"ER", "ER multi stud", "NeckWear", "Ring", "WristWear"}
choose from list ItemTypesList with prompt "What are you mostly working on today?"
if the result is false then
return
else
set ItemType to result as text
log ItemType
end if
replaceText("choose from list ItemTypesList with prompt \"Choose Item\" default items {\"ER\"}", "choose from list ItemTypesList with prompt \"Choose Item\" default items {\"" & ItemType & "\"}", theScript)
on replaceText(search_string, replacement_text, this_document)
tell application "AppleScript Editor"
open this_document
set AppleScript's text item delimiters to the search_string
set this_text to the text of the front document as list
set AppleScript's text item delimiters to the replacement_text
set the text of the front document to (this_text as string)
save saveScript
end tell
end replaceTextI think I might be getting a little confused
This is the scipt to run at login (as an app)
set scriptToModify to load script ((path to me)'s POSIX path & "Contents/Resources/Scripts/defaultScript.scpt")
set scriptToModify's ItemTypesList to {"ER", "ER multi stud", "NeckWear", "Ring", "WristWear"}
choose from list ItemTypesList with prompt "What are you mostly working on today?"
store script scriptToModify in ((path to home folder)'s POSIX path & "Workflow") with replacing
Then this is the script held in the bundle
set ItemTypesList to {"ER", "ER multi stud", "NeckWear", "Ring", "WristWear"}
choose from list ItemTypesList with prompt "Choose Item" default items {"XXXXX"}
--the XXXXX part above is the area i hope to change.
if the result is false then
return
else
set ItemType to result as text
if ItemType is equal to "ER" then
set BorderIncrease to 40
else if ItemType is equal to "ER multi stud" then
set BorderIncrease to 20
else if ItemType is equal to "NeckWear" then
set BorderIncrease to 10
else if ItemType is equal to "Ring" then
set BorderIncrease to 40
else if ItemType is equal to "WristWear" then
set BorderIncrease to 20
end if
end if -
Applescript - trying to horizontally align all the text in a text frame
I've tried the following snippet along with several others:
tell application "Adobe InDesign CS5.5"
tell the active document
set Text_Frame to the text frame "PH"
tell Text_Frame
set theLines to every line
if (theTextPos = "B") then
tell theLines to set justification to left align
else
tell theLines to set justification to center align
end if
end tell
end tell
end tell
Throws errors about setting classes.
ie
error "Can’t set «class paln» of {\"MISSOULA COMMUNITY PHYSICIANS
\", \"CENTER NO. 2
\", \"CONDOMINIUM ASSOCIATION
\", \"2827 FORT MISSOULA ROAD
\", \"MISSOULA, MT 59804
\"} to «constant mAOHcent»." number -10006 from «class paln» of {"MISSOULA COMMUNITY PHYSICIANS
", "CENTER NO. 2
", "CONDOMINIUM ASSOCIATION
", "2827 FORT MISSOULA ROAD
", "MISSOULA, MT 59804
All I'm trying to do is center the text in a text frame if a condition is met, else left align it if another condition is met.
Any suggestions woudl be appreciated.Don't get the lines first:
if (theTextPos = "B") then
set justification of every line to left align
else
set justification of every line to center align
end if -
Working in InDesign CS5
Still banging my head against the wall over this last bit of code I need to figure out to finish a much larger script. What I'm looking to do is take a paragraph ('contents' from looping in larger script) from one text frame and duplicate it to the END of a second text frame (represented by 'Ad_Box'). The only thing I've gotten to semi-work is this:
set insertion point -1 of Ad_Box to contents
The problems with the above script are:
1. Minor problem (can be worked around in InDesign CS5) - The script does not keep the formatting from the original paragraph that I want duplicated. The paragraph style of all "inserted" paragraphs is set to default
2. The big problem - When the second text frame is too small for a particular word in original paragraph, the paragraph is moved to the wrong position in the text frame when the script completes, which is moving 4 paragraphs in total (this one baffles me). In other words, if I'm running script to be p1, p2, p3, p4 and p2 had a word too long to fit in text frame, on completion it will look like p1, p3, p4, p2.
This is why I'm hoping to use the DUPLICATE command in some capacity, but I'm stumped. I set up a dialogue prompt to help me debug, and whenever I use the DUPLICATE command my script skips right over the dialogue, so I know it's not reading properly. This is what I've tried with no luck. Any help would be greatly appreciated.
duplicate contents to insertion point -1 of Ad_BoxMary, you were absolutely correct!! This fixes the problem of placing the contents into the wrong spot, AND it runs the script much faster too! Thank you.
However it is still not carrying over my "applied paragraph style" that is on "contents". Does 'insertion point' not work this way?
What looks like is happening is that in the InDesign app, whatever my default selected paragraph style is is what the insertion point type is placing as.
I might try to set my applied paragraph style after the "last insertion point" call and see if that works. I'll update this reporting results -
Problem replacing content in text frame
I am bumping my head against this. Its something I thought I know. I have a labeled text frame when I alert(mySpineTxt.getElements()); it tells me [object TextFrame] that sounds good to me then I use this
if(mySpineTxt.getElements().length != 0){
with(mySpineTxt.parentStory.words.itemByRange(0,0)){
mySpineTxt.contents=(String(myResp))
and it tells me that mySpineTxt does not support parentStory. I think it should.
Please add any corrections that I am missing.#targetengine "session"
//Creates a simple event listener.
main();
function main(){
var myEventListener = app.addEventListener("beforePrint", dateChanges, false);
var myEventListener = app.addEventListener("beforeSave", dateChanges, false);
//var myEventKill = app.addEventListener("beforeClose", killDate, false);
function dateChanges(){
var myDocument = app.activeDocument;
var myPageItems = myDocument.pageItems.item("myDateLabel");
if(myPageItems==myPageItems){
if(myPageItems.getElements().length != 0){
//alert ("I want to change your date")
var myDateText=myPageItems
var myDate=new Date();
myDate=String(myDate);
myDate=myDate.slice(0,15);
myDate=myDate.slice(4,15);
alert(myDateText);
with(myDateText.parentStory.words.itemByRange(2,4)){
contents=( ""+myDate)
}//ending bracket for dateChanges function
function killDate(){
app.removeEventListener("beforePrint", dateChanges, false);}
this is an event listner that changes the date. This works when I use myDateText.parentStory when I plug it in to the other script i am using same stuff. it doesn't work its object is also listed as a page item. -
Deleting text frames without a specific fill color
I was wondering if someone might be able to tell me a simple way in javascript to scan through all the text frame in my active document that are NOT filled with the following RGB values...
fillColor.red = 11
fillColor.green = 142
fillColor.blue = 196
Windows 7 64 bit, CS4I changed my concept to make it more dynamic for my purpose. I am checking to see if the fillColor typename is RGBColor or GrayColor. I am deleting anything that is GrayColor. Thought I would share the code for the community to use as you wish. Hope it helps somebody!
var doc = app.activeDocument
var allText = doc.textFrames;
var readFillColor = [];
for(i=0; i<allText.length; i++)
textItemsRange = allText[i].textRange;
readFillColor[i] = textItemsRange.characterAttributes.fillColor
if(readFillColor[i].typename == "RGBColor")
//alert("Found RGBColor")
else{
//alert("Found GrayColor")
textItemsRange.remove(); -
Indesign CS3 text frame parameters and export PDF
could use some help with the following:
I need to edit and export a large number (7000) Indesign documents (one page)
1. check for locked text frames and unlock
2. group all text frames
3. set grouped text frames at x=8 millimeters, y 10 milimeters
4. export the documents to PDF in a subfolder called "Out"
5. save and close the documents in the same subfolder as an Indesign CS3 document (orig is CS2)
This is what I've been trying soo far:
Now only checking one text frame - should be all text frames
"close document 1 saving yes" doesn't work because the originals are from CS2
I get a PDF called "Adobe Indesign SC3"
set processFolder to choose folder with prompt "Choose a folder that contains Innd Docs to process"
tell application "Finder"
if not (exists folder "OUT" of processFolder) then
make new folder at processFolder with properties {name:"OUT"}
end if
set the destination_folder to folder "OUT" of processFolder as alias
end tell
tell application "Finder"
try
set listFiles to (files of contents of processFolder) as alias list
on error
set listFiles to (files of contents of processFolder) as alias as list
end try
repeat with thisFile in listFiles
tell application "Adobe InDesign CS3"
with timeout of 120 seconds
activate
set properties of view preferences to {horizontal measurement units:millimeters, vertical measurement units:millimeters, ruler origin:page origin}
open thisFile
set myDoc to document 1
set docName to name
tell myDoc
set transform reference point of layout window 1 to top left anchor
set myBox to text frame 1 of page 1
set properties of myBox to {locked:false}
move myBox to {8, 10}
end tell
export document 1 format PDF type to (destination_folder as string) & docName & ".pdf" using PDF export preset "[Drukwerkkwaliteit]" without showing options
close document 1 saving yes
tell application "Finder" to move thisFile to destination_folder with replacing
end timeout
end tell
end repeat
end tell
end
end
Any help is greatly appreciated - Doing this manually is a lot of work!!!!!
PeterYou're asking for the name of the application, not the document -- you need<br />to do it after your "tell myDoc".<br /><br />You could also get the name from the alias you open, rather than the open<br />document, something like:<br /><br />repeat with thisFile in listFiles<br />set oldDelims to AppleScript's text item delimiters<br />set AppleScript's text item delimiters to {":"}<br />set docName to text item -1 of (thisFile as Unicode text)<br />set AppleScript's text item delimiters to oldDelims<br /><br />You should also move your "set properties of view preferences" line to after<br />your "tell myDoc".<br /><br />-- <br />Shane Stanley <[email protected]>
-
Question about an image in a text frame
hi, everybody,<br /> i want to get the UIDRef to an image in a text frame and i used the codes below: <br /><br />UIDRef imageUIDRef = UIDRef(database, ownedList[i].fUID);;<br /> InterfacePtr<IImageDataAccess> imageAccess(imageUIDRef, IID_IIMAGEDATAACCESS);<br /><br />(ownedList[i] is the list which contains the inline boss i want to get)<br /><br />here i always get an imageAccess == nil, i think it is caused by the invalid imageUIDRef.<br /><br />can someone tell me how to resolve this??? or tell me another way to get the UIDRef to the image.<br /><br />Thanks a lot!!
Oliver and Quake,
during initial development, you frequently reach a method that just returns a UID, UIDList etc. That approach with IUnknown and debugclassutil is a way to determine the boss class of such a UID in clear text, for your further research.
You would then go to the documentation (programming guide, API docs, samples) and find out about the typical use of this boss class. This mainly means you find the list of interfaces supported by the boss class.
Open docs/references/sdkdocs/html/classIImageAttributes.html
See at the bottom that this interface is on kImageItem and some strange others, but not on kInlineBoss.
Open docs/references/sdkdocs/html/classkInlineBoss.html
See it has an interface IHierarchy.
If you do not find your desired interface on a boss class, that means you have to navigate to a different boss object.
IHierarchy is an important interface for navigation in the page, because it implements the page item tree. So when the programming guide tells you to use IHierarchy to find an image from the inline boss, follow that path. On the other hand, it is just one interface of many, so you can't do that generalization that it fits all purposes. Even on the page tree you can encounter inlines, text on path that form a separate page item tree. To know the best path is called experience.
In the release code you should not wire to specific ::GetClass values (as seen somewhere in this thread). Instead, you have an expectation of interfaces, and if an object supports them it is ok. Let's say I implement a new page item boss to support strange text flow or different image types. That page item will still have bounds. If you need bounds, find the appropriate interface and just use it. The same goes for attributes - if you deal with attributes in general and encounter a new attribute that supports the standard interfaces, just let it through.
Oliver, I don't even know the boss class returned by IIDXMLElement->GetContentItem() for your specific purposes, but I would take the same approach. I use a plugin grown in the past 5 years that visits most interfaces and hooks into all notifications I ever encountered. This produces tons of output, but otherwise it is the same as with simple debugclassutil.
An important issue is the preparation of test data. You just have to know that XML elements can point to many things in the InDesign universe, so tag a few tables, inlines, TOP, page items that use standoff and so forth, and see what you get. WYSIWYG at its best.
Of course I could spend the whole day constructing examples, doing the analysis and copy-paste-post code. At least for me that is beyond the scope of the forum - maybe Adobe will some time replace Ken, otherwise there are the developer support cases. As I am not sponsored by paycheck, most of the time I try to keep my answers to short keywords or plain text - you will rarely see code from me. If you need that, there have been several postings on this list, and I am also available for consulting.
Dirk -
ID CS3 - text wrap doesn't work at the end of a long multi-columned text frame
Did a search - don't think this specific issue has been addressed:
We design large graphics often used on walls. When working with a text frame that that was 11 feet long and had 8 columns, text wrap would not work on an image placed in the last column. The same image with the same text wrap applied will work fine anywhere else in the text frame. I found that if I shortened the width of the text frame a little bit at a time eventually it would work, but there doesn't seem to be a specific cut-off width - sometimes the last column won't text wrap when the frame is 115 inches wide and sometimes it doesn't work when the frame is only 80 inches wide. Again, all of the other columns work fine. I have tried all of the obvious stuff, the only variable between the columns that wrap and the one that doesn't is it's position at the end of the text frame.
We have gotten around this issue by using multiple threaded frames instead of one long frame with multiple columns, but I am curious if anyone else has run into this or might know what the issue is.
thanksDid a search - don't think this specific issue has been addressed:
We design large graphics often used on walls. When working with a text frame that that was 11 feet long and had 8 columns, text wrap would not work on an image placed in the last column. The same image with the same text wrap applied will work fine anywhere else in the text frame. I found that if I shortened the width of the text frame a little bit at a time eventually it would work, but there doesn't seem to be a specific cut-off width - sometimes the last column won't text wrap when the frame is 115 inches wide and sometimes it doesn't work when the frame is only 80 inches wide. Again, all of the other columns work fine. I have tried all of the obvious stuff, the only variable between the columns that wrap and the one that doesn't is it's position at the end of the text frame.
We have gotten around this issue by using multiple threaded frames instead of one long frame with multiple columns, but I am curious if anyone else has run into this or might know what the issue is.
thanks
Maybe you are looking for
-
Scanning multiple pages into PDF
I am trying to scan multiple pages into one PDF. I read the help document - which states that to add pages, one clicks on the "+" button on the left. However, my software does not show the "+" button. I have the latest version of the software. What's
-
Error while posting invoice against PO
Hi While posting an invoice against PO #, it is giving error as Field Prof.Segmt is a required field for G/L account Company code XXXX XXXXXX(GL master #) Message no. F5808. Can anyone provide me the possible solution for this. I would appreciate you
-
How do I make the internal mic on my macbook air sustain better when recording on garage band? I have been recording an acoustic guitar and listening back, the mic seems to pick it up well naturally for 1 or 2 seconds then dramatically drop out.
-
Simple problem writing "#N/A" to a .txt file
Hi, I would like to write the string : #N/A in a text file so that when I open the text file whith Excel, those points don't appear on the plot. Whith the VI I have attached, those #N/A points are considered as 0 on the excel plot. Whereas if I write
-
Hello, I've been doing this in Photoshop for a long while now, but am curious as to how to resize photos using iPhoto 6. I don't seen an obvious way to do this, but I'm probably just missing it. What I want to do is take an image at 2816x2112 and res