Created
January 15, 2013 15:12
-
-
Save ttscoff/4539300 to your computer and use it in GitHub Desktop.
Copy the contents of any text file to the clipboard, intended for use as an OS X System Service
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
# A stupid script that actually makes a handy system service | |
# Use it to right click files and extract their text content to the clipboard | |
# Brett Terpstra 2013, no rights reserved | |
txtcount=`file "$@"|grep -c text` | |
response=0 | |
msg="" | |
if [ $txtcount -eq $# ]; then | |
cat "$@"|pbcopy | |
if [ "$?" -ne "0" ]; then | |
msg="Error running command" | |
response=1 | |
else | |
[ $# -gt 1 ] && plur="$# files" || plur="the file" | |
msg="The contents of $plur are on the clipboard" | |
fi | |
else | |
msg="One or more files were not recognized as plain text" | |
response=1 | |
fi | |
if [ $response -eq 0 ]; then | |
sound="Glass" | |
status="successful" | |
else | |
sound="Basso" | |
status="failed" | |
fi | |
afplay /System/Library/Sounds/$sound.aiff | |
[[ -f /usr/local/bin/growlnotify ]] && /usr/local/bin/growlnotify -m "$msg" -t "Clip $status" | |
# If you have growlnotify installed, you'll get a message in addition to a chime or buzz | |
# Also see <http://brettterpstra.com/2012/08/02/a-drop-in-growlnotify-replacement-for-mountain-lion-notifications/> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment