Last active
February 4, 2017 10:21
-
-
Save unforswearing/43af571e92f8a081f4e5 to your computer and use it in GitHub Desktop.
an automator script to wrap punctuation around text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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