Hi
I’m very new to AppleScript and I get a problem with my (almost) first script.
tell application "BBEdit"
open "/Users/me/myFile.html"
set search_strings to {"placeHolder1", "placeHolder2", "placeHolder3"}
set replace_strings to {"myText1", "myText2", "myText3"}
end tell
The file opens, but the placeHolders are not replaced.
I guess I missed something… but the script is so explicit that I don’t find what.
Thanks for your help
Philippe
Model: MacPro
AppleScript: 2.3(118)
Browser: Firefox 5.0.1
Operating System: Mac OS X (10.6)
Hi, Philippe.
In your code example, search parameters get defined, but no actual search is performed; essentially, it’s all noun and no verb.
I don’t have BBEdit, but I use its descendant, TextWrangler, and I suspect my example may be interchangeable. Trade “BBEdit” for “TextWrangler”, then try this:
--set parameters
set search_strings to {"placeHolder1", "placeHolder2", "placeHolder3"}
set replace_strings to {"myText1", "myText2", "myText3"}
--open --Your initial file path was styled with slashes”like a POSIX path”but the Mac OS uses colon separators
tell application "TextWrangler" to open file "Macintosh HD:Users:me:myFile.html"
--find & replace
repeat with x from 1 to count search_strings
tell application "TextWrangler"'s document 1
replace (search_strings's item x) using (replace_strings's item x) searching in it ¬
options {returning results:0} saving no
end tell
end repeat
--close with changes
tell application "TextWrangler"'s document 1 to close (save)
Hi Marc,
Great ! it works fine.
Many thanks also for comments in script - very useful.
Regards
Philippe