Reputation: 23
I'm trying to write a "simple" applescript that will find a text frame in InDesign that has a certain property and then change the Paragraph style of that particular text frame. I know that the if statement is correct because I use it for other applescripts. So I have a text frame with the object style called "PriceBox". If the text frame contains a slash "/" in it, I want to change the Paragraph style to "2for". I confirmed that the paragraph style exists in the document. However, when I run the script, I get this error:
error "Can’t set «class psty» of {«class txtf» id 6905 of «class sprd» id 6891 of document id 4 of application \"Adobe InDesign CC 2015\"} to \"2for\"." number -10006 from «class psty» of {«class txtf» id 6905 of «class sprd» id 6891 of document id 4} to «class 2for»
I've tried variations of the "set paragraph style" script and none of them seem to work. Please help! =) Thank you!
tell application "Adobe InDesign CC 2015"
tell active document
set horizontal measurement units of view preferences to inches
set vertical measurement units of view preferences to inches
repeat with x from 1 to count pages
set ThisPage to page x
tell ThisPage
if exists (text frames whose (name of applied object style is "PriceBox" and contents contains "/$")) then
set paragraph style of (get text frames whose name of applied object style is "PriceBox") to "2for"
end if
end tell
end repeat
end tell
end tell
Upvotes: 1
Views: 1011
Reputation: 1391
You are testing for "/$" not just "/".
You can't apply paragraph style to a text frame directly. You will need to use paragraphs.
Also need to loop through the frames
tell application "Adobe InDesign CC 2015"
tell active document
set horizontal measurement units of view preferences to inches
set vertical measurement units of view preferences to inches
repeat with x from 1 to count pages
set ThisPage to page x
tell ThisPage
if exists (text frames whose (name of applied object style is "PriceBox" and contents contains "/$")) then
set myFrames to (text frames whose (name of applied object style is "PriceBox" and contents contains "/$")))
tell myFrames
repeat with r from 1 to count items
set applied paragraph style of paragraphs of item r of myFrames to "2For"
end repeat
end tell
end if
end tell
end repeat
end tell
end tell
Upvotes: 0