Skip to content

Instantly share code, notes, and snippets.

@unforswearing
Last active February 4, 2017 10:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unforswearing/43af571e92f8a081f4e5 to your computer and use it in GitHub Desktop.
Save unforswearing/43af571e92f8a081f4e5 to your computer and use it in GitHub Desktop.
an automator script to wrap punctuation around text
on run {input}
# this script handles cancellations properly, but is much slower than the shell script version
try
set bloog to (choose from list {"double-quote \"\"", "single-quote ''", "parenthesis ()", "curly-brace {}", "brace []", "angled-bracket <>"} with title "Select an Item" OK button name "Wrap" default items {"double-quote"} with empty selection allowed)
if bloog is false then
error number -128
end if
set bloog to do shell script "echo " & bloog & " | sed 's/[[:punct:]]. *$/ /g;s/[[:space:]]//g'"
if bloog contains "double-quote" then
set wrap to do shell script "echo " & input & " | sed 's/^/\\\"/;s/$/\\\"/'"
else if bloog contains "single-quote" then
set wrap to do shell script "echo " & input & " | sed \"s/^/\\'/;s/$/\\'/\""
else if bloog contains "parenthesis" then
set wrap to do shell script "echo " & input & " | sed 's/^/\\(/;s/$/\\)/'"
else if bloog contains "curly-brace" then
set wrap to do shell script "echo " & input & " | sed 's/^/\\{/;s/$/\\}/'"
else if bloog contains "brace" then
set wrap to do shell script "echo " & input & " | sed 's/^/\\[/;s/$/\\]/'"
else if bloog contains "angled-bracket" then
set wrap to do shell script "echo " & input & " | sed 's/^/\\</;s/$/\\>/'"
end if
return wrap
end try
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment