I've been having fun with Apple's new Snow Leopard, the latest upgrade of their OS X operating system.
One of the big improvements they've made is in simplifying the way that users can easily automate repetitive tasks.
One of the minor pains in my butt has been the online statements from bank accounts and other companies. They download to the hard drive with an odd name, like STATEMENT.PDF; then I have to manually rename them and move them into the folder where I keep them.
Sounds like a great prospect for automation.
After some experimentation, I decided that a shell script attached to a Folder Action was the way to go.
My script looks for certain file names in the Downloads directory and automatically renames them to include today's date and the name of the company. For example, when it sees a file named JPMCStatement.pdf it will move it into the ${HOME}/Documents/BillingStatements/AmazonVisa folder and change its name to AmazonVisa-2009-08-30.pdf.
And for good measure, it pops open the folder in the Finder with the new file highlighted.
Here's what I did.
Start up Automator and select Folder Action from its opening screen.
Select the folder that you want to monitor from the Choose folder popup.
Now drag a Run Shell Script action (under Library Utilities) and drop it as the first item in your workflow. Set it to Pass input as arguments.
Copy and paste the following code into that action, making the changes needed to customize it for your needs. (I tried to make it fairly easy to modify by editing the values of variables and adding more statements to the case structure, but it is a shell script after all.) Actually you are probably better off by creating a shell script file and testing it in the terminal first; just uncomment those echo statements to test.
DATE=`date "+%Y-%m-%d"`
SRC_DIR="${HOME}/Downloads/"
DEST_DIR="${HOME}/Documents/BillingStatements/"
TARGET_FILE="none"
BASENAME=`basename ${1}`
ORG_FILE_NAME=${1}
case ${BASENAME}
in
"JPMCStatement.pdf") TARGET_FILE="AmazonVisa";;
"processStmtExpressAction.do") TARGET_FILE="Dish";;
"STATEMENT.PDF") TARGET_FILE="TDBank";;
#Add more cases before the esac
esac
TARGET_DIR="${DEST_DIR}${TARGET_FILE}/"
#echo ${TARGET_FILE}
#echo "${TARGET_FILE}-${DATE}.pdf"
#echo ${ORG_FILE_NAME}
#exit
if test ${TARGET_FILE} != "none"
then
echo "Original file: ${ORG_FILE_NAME}" >>${SRC_DIR}my.log
NEW_FILE_PATH_NAME="${TARGET_DIR}${TARGET_FILE}-${DATE}.pdf"
mv ${ORG_FILE_NAME} ${NEW_FILE_PATH_NAME} 2>>${SRC_DIR}my.log
echo "Processed file: ${NEW_FILE_PATH_NAME}" >>${SRC_DIR}my.log
echo "${NEW_FILE_PATH_NAME}"
fi
Now drag a Reveal Finder Items action (under Library Files and Folders) as the next item in your workflow. Save it, and with a little bit of testing, you should be good to go!
Then again, it is a shell script...



