Skip to content

Instantly share code, notes, and snippets.

@madvas
Created May 6, 2015 20:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save madvas/8e1d8c680a35a2d45b09 to your computer and use it in GitHub Desktop.
Save madvas/8e1d8c680a35a2d45b09 to your computer and use it in GitHub Desktop.
Applescript escape XML special chars
on escapeString(toEscape)
set res to replaceChars(toEscape, "\"", """)
set res to replaceChars(res, "'", "'")
set res to replaceChars(res, "&", "&")
set res to replaceChars(res, ">", ">")
set res to replaceChars(res, "<", "&lt;")
return res
end escapeString
on replaceChars(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end replaceChars
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment