Skip to content

Instantly share code, notes, and snippets.

@thomaswitt
Created November 6, 2013 10:18
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 thomaswitt/7333822 to your computer and use it in GitHub Desktop.
Save thomaswitt/7333822 to your computer and use it in GitHub Desktop.
Apple Script String Helpers
on replace(sourcetext, search, replacement)
set oldDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to the search
set the textItemList to every text item of the sourcetext
set AppleScript's text item delimiters to the replacement
set the output to the textItemList as string
set AppleScript's text item delimiters to oldDelim
return output
end replace
on strip_spaces(aLine)
--strip lead spaces
set ods to AppleScript's text item delimiters
repeat until first character of aLine is not " "
set AppleScript's text item delimiters to {""}
set aLine to (characters 2 thru -1 of aLine as string)
set AppleScript's text item delimiters to ods
end repeat
--strip tail spaces
set ods to AppleScript's text item delimiters
repeat until last character of aLine is not " "
log aLine
set AppleScript's text item delimiters to {""}
set aLine to (characters 1 thru -2 of aLine as string)
set AppleScript's text item delimiters to ods
end repeat
return aLine
end strip_spaces
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment