Created
November 22, 2020 13:39
-
-
Save tjluoma/edc975079a2e293ce67ed2e647f1d26d to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env zsh -f | |
# Purpose: This script will email all PDFs from one folder to a designated recipient | |
# | |
# Note: this script uses 'emate' which is a part of MailMate.app (https://freron.com) | |
# and assumes that the app is already properly configured to send email. | |
# change this to the email address you want to send the files to | |
MAIL_TO='[email protected]' | |
# this is the folder where the PDFs will be sent from | |
SOURCE_DIR="$HOME/Desktop/Send" | |
# this is the folder where the PDFs will be moved to after they are sent | |
MOVE_TO="$HOME/Desktop/Sent" | |
## you should not _have_ to edit anything below this line. | |
NAME="$0:t:r" | |
PATH="/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin" | |
if [[ -x '/Applications/MailMate.app/Contents/Resources/emate' ]] | |
then | |
alias emate='/Applications/MailMate.app/Contents/Resources/emate' | |
else | |
if [[ ! -d '/Applications/MailMate.app' ]] | |
then | |
echo "$NAME: MailMate.app is not installed" >>/dev/stderr | |
else | |
echo "$NAME: 'emate' not found (but MailMate.app is installed)" >>/dev/stderr | |
fi | |
exit 2 | |
fi | |
if [[ ! -d "$SOURCE_DIR" ]] | |
then | |
echo "$NAME: '$SOURCE_DIR' does not exist." >>/dev/stderr | |
exit 2 | |
fi | |
if [[ ! -d "$MOVE_TO" ]] | |
then | |
# if the destination folder doesn't exist, create it | |
mkdir -p "$MOVE_TO" | |
fi | |
cd "$SOURCE_DIR" | |
command ls -1 | egrep '\.pdf$' | while read line | |
do | |
# this is the full filename with extension | |
FILENAME="$line" | |
# this is the filename withOUT the extension | |
SHORT="$FILENAME:r" | |
# if you want to see the email message before it is sent, | |
# remove '--send-now' from the next line | |
emate mailto --to "$MAIL_TO" --subject "Results Completed - $SHORT" --send-now "$FILENAME" | |
# Note that there will be no 'body' to the email message, only the attachment. | |
EXIT="$?" | |
if [[ "$EXIT" == "0" ]] | |
then | |
echo "$NAME: Sent '$FILENAME' successfully" | |
mv -vn "$FILENAME" "$MOVE_TO" | |
else | |
echo "$NAME: failed to send '$FILENAME' (\$EXIT = $EXIT)" >>/dev/stderr | |
fi | |
done | |
exit 0 | |
#EOF | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment