You are here:
> Bash scripts
> Keeping organised with scanning and filing
> Bash scripts
> Keeping organised with scanning and filing
It seemed like a reasonably good idea to scan in any important receipts and keeping a file of them on the computer instead of whording lots of little bits of paper that are likely to get lost. Oh, and also, it's fun to use a paper shredder.
If something isn't easy to do and requests attention on a repeated basis, I won't get it done; for this reason, I made this as easy as possible :o)
What you need: A Linux box :), ImageMagick, sane
What it does:
- create (if doesn't exist) a folder for the year
- create (if doesn't exist) a folder for the month
- scan the document in
- convert the document to a PNG file
- save the image with the name receipt_<ddDDD>.png (with an appended number for the count of docs scanned that day)
- ddDDD is numeric representation of the day DDD is a textual representation. e.g. 04Thu
You will need to change a couple of settings at the top of the script and should be good to go; however, I would recommend playing with the arguments passed to 'convert'
#!/bin/bash #Set the folder and filename to save to PARENTFOLDER="/home/rdy/Desktop/Dropbox/documents/receipts/scanned/`date +%Y`" FILENAME="receipt_`date +%d%a`.png" #Body of the script, do not change below this line ROOTFOLDER="$PARENTFOLDER/`date +%b`" COUNTER=0 if [ ! -G $ROOTFOLDER ]; then if [ ! -G $PARENTFOLDER ]; then mkdir $PARENTFOLDER #create folder for year fi mkdir $ROOTFOLDER #create folder for month fi while [ -G "$ROOTFOLDER/$FILENAME" ]; do let COUNTER=COUNTER+1 FILENAME="receipt_`date +%d%a`_$COUNTER.png" #if the filename already exists, append the next number in the sequence done rm /tmp/scanimage.tiff #temporary image echo "scanning image.." scanimage --mode color --format tiff > /tmp/scanimage.tiff #perform the scan and save a temp copy convert /tmp/scanimage.tiff -fuzz 25% -trim +repage -gravity east -chop 40x0 -bordercolor '#86838f' -border 5x5 -scale 1024 "$ROOTFOLDER/$FILENAME" #convert the image to a png to reduce the size #check to see if the operation was successful if [ -G "$ROOTFOLDER/$FILENAME" ]; then echo "Scanned image saved to $ROOTFOLDER/$FILENAME..." #success echo "Press enter to exit..." else echo "Something went wrong, the file was not saved. Please try again" #FAIL echo "Press enter to exit..."fi
:: Page tags: bash :: Page last modified on Wed, 20 Jan 2010 ::