Search code examples
scriptingtextwranglermacos-sierra

Find and Replace script for textWrangler


I'm trying to make a script that will find and replace some xml structure.

I've made it all flat, no spaces, no return.

So far I've made :

tell application "TextWrangler"
    replace text "<key>amenity</key><string>drinking_water</string>" using text "<key>ico</key>
<string>NPpotableGPS30</string>"
end tell

The script editor says :

  Error in TextWrangler : text "<key>amenity</key><string>drinking_water</string>" don't have the message « replace ».

This is my first script so I'm probably doing something wrong, but what ?


Solution

  • The key "text" seems to be misplaced. The following appears to correctly work (the sequence from searching onwards being optional for defining the document to process, according to actual working situation):

    tell application "TextWrangler"
     replace "<key>amenity</key><string>drinking_water</string>" using "<key>ico</key><string>NPpotableGPS30</string>" searching in text 1 of text document "..." options {search mode:grep, starting at top:true}
    end tell