Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

FrogNL

macrumors newbie
Original poster
Jun 19, 2010
14
0
Hi everyone,

I'm trying to find and replace a string of text in a Pages document using the Scripting Bridge. I've been able to figure out how to get a list of all words (so that I can iterate over them and find out whether it's the word I want to replace), but I can't find any method to replace a word. This must be possible, since you can do it with Applescript and Scripting Bridge should be able to do the same.

I've got the following code:

Code:
PagesApplication *pages = [SBApplication applicationWithBundleIdentifier:@"com.apple.iWork.Pages"];
PagesDocument *document = [pages open:inputURL];
PagesText *bodyText = [document bodyText];
SBElementArray *words = [bodyText words];

NSLog(@"%lu words", [words count]);

for (PagesWord *word in [bodyText words]) {
	NSLog(@"%@", [[word properties] objectForKey:@"contents"]);
}

I want to change the contents property of a word. How can I do this?

Thanks!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.