Skip to content

Instantly share code, notes, and snippets.

@n8henrie
Created July 7, 2016 19:32
Show Gist options
  • Save n8henrie/a80307ead59df8f055a2b58688a495a9 to your computer and use it in GitHub Desktop.
Save n8henrie/a80307ead59df8f055a2b58688a495a9 to your computer and use it in GitHub Desktop.
Quicksilver Action to strip leading and trailing whitespace
property test_block_text : "
this and
that and
asdf
"
on process_text(block_text)
-- AppleScript and Quicksilver are using code "e2 80 a8" as linebreak for some reason
-- inspect by piping to `hexdump -C` and viewing with `echo -e`
set perl to "/usr/bin/perl -0777 -pe 's#(^[[:space:]\\xe2\\x80\\xa8]*)|([[:space:]\\xe2\\x80\\xa8])*$##g' <<<"
set result to do shell script perl & quoted form of block_text
return result
end process_text
using terms from application "Quicksilver"
on get direct types
return {"NSStringPboardType"}
end get direct types
on process text block_text
try
set result to process_text(block_text)
tell application "Quicksilver" to set selection to result
on error a number b
activate
display dialog a with title "error with your QS action script"
end try
end process text
end using terms from
on run
set result to process_text(test_block_text)
tell application "Quicksilver" to set selection to result
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment