Skip to content

Instantly share code, notes, and snippets.

@cazepeda
Last active January 9, 2024 05:46
Show Gist options
  • Save cazepeda/55a0644c5ef0d2db7b19402d331709ef to your computer and use it in GitHub Desktop.
Save cazepeda/55a0644c5ef0d2db7b19402d331709ef to your computer and use it in GitHub Desktop.
Applescript to convert spaces, @, ?, ', to hyphens and uppercase to lowercase.
on run {input}
set input to replaceText(" ", "-", input as string)
set input to replaceText(".", "", input as string)
set input to replaceText(":", "", input as string)
set input to replaceText(",", "", input as string)
set input to replaceText("@", "at", input as string)
set input to replaceText("'", "", input as string)
set input to replaceText("&", "and", input as string)
set input to replaceText("?", "", input as string)
set input to do shell script "echo " & quoted form of input & " | tr '[:upper:]' '[:lower:]'"
end run
on replaceText(find, replace, textString)
set prevTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to find
set textString to text items of textString
set AppleScript's text item delimiters to replace
set textString to "" & textString
set AppleScript's text item delimiters to prevTIDs
return textString
end replaceText
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment