In InDesign CS3, the Find/Change box allows you to specify All Docments, Document, Story, To End of Story. It seems to default to Document.
Is there a way to script the “Story” selection when scripting a Find/Change?
I only want to run the Find/Changes on the currently selected story as defined here…
tell application "Adobe InDesign CS3"
activate
tell parent story of text frame of selection
--I typically place formatting to the story in this area...
--Find/Change Settings:
tell application "Adobe InDesign CS3"
--Clear the Find/Change fields
set find text preferences to nothing
set change text preferences to nothing
--Search for the string "Text"
set find what of find text preferences to "Text"
set change to of change text preferences to "Text"
--set the find options
set case sensitive of find change text options to true
set include footnotes of find change text options to false
set include hidden layers of find change text options to false
set include locked layers for find of find change text options to false
set include locked stories for find of find change text options to false
set whole word of find change text options to true
--Do It
change text
set find text preferences to nothing
set change text preferences to nothing
end tell
end tell
end tell
I’m hoping there’s a simple one-line code to add. Thanks
Model: G5
AppleScript: 2.1.2
Browser: Firefox 3.0.6
Operating System: Mac OS X (10.5)
You need to direct the find to an object. I don’t have access to ID at the moment, but I think this will work.
tell application "Adobe InDesign CS3"
--Clear the Find/Change fields
set find text preferences to nothing
set change text preferences to nothing
--Set FindWhat/ChangeTo values
set find what of find text preferences to "Text"
set change to of change text preferences to "SomethingOtherThantheFindWhatValue"
--set the find options
set case sensitive of find change text options to true
set include footnotes of find change text options to false
set include hidden layers of find change text options to false
set include locked layers for find of find change text options to false
set include locked stories for find of find change text options to false
set whole word of find change text options to true
--Do It
tell document 1's selection's parent story to change text
set find text preferences to nothing
set change text preferences to nothing
end
Thanks Marc! It works perfectly now. That seems more obvious than I thought it would be. I tweaked it a little to address the same selected object in my original. I placed it in a try to avoid the occasional “can’t find this” error.
Here’s my final change command:
--DO IT
try
tell parent story of item 1 of selection to change text
end try
I was looking for the same topic when I came across this post. Everything works fine as long as I run your script from my AppleScript-Editor but now I want to implement it into my Xcode project where the selection should be connected to a ComboBox0. The app compiles without issues but when I run the action still the whole document is searched even if I select “selected text frame” in my ComboBox0.
Does anyone see the problem?
on ersetzen(Var1, Var2)
set theText to ComboBox0's stringValue() as text
if theText is equal to "whole document" then
tell application id "com.adobe.InDesign"
set myTextFrame to text frame 1 of active document
set find text preferences to nothing
set change text preferences to nothing
set find what of find text preferences to Var1
set change to of change text preferences to Var2
select text of myTextFrame
tell active document
set myFoundItems to change text
end tell
set find text preferences to nothing
set change text preferences to nothing
end tell
else if theText is equal to "selected text frame" then
tell application id "com.adobe.InDesign"
set find text preferences to nothing
set change text preferences to nothing
set find what of find text preferences to Var1
set change to of change text preferences to Var2
tell document 1's selection's parent story to change text
set find text preferences to nothing
set change text preferences to nothing
end tell
end if
end ersetzen