Skip to content

Instantly share code, notes, and snippets.

@mingsai
Created May 28, 2020 11:33
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 mingsai/edab1786486e957c14f7a6583a23e0f6 to your computer and use it in GitHub Desktop.
Save mingsai/edab1786486e957c14f7a6583a23e0f6 to your computer and use it in GitHub Desktop.
Applescript: Replace text handler
-- Replaces a substring with another substring
(*
set my_var to StringsLib's replace_text(some_text, "abc", "def")
*)
on replace_text(this_text, search_string, replacement_string)
set prevTIDs to AppleScript's text item delimiters
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 prevTIDs
return this_text
end replace_text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment