autorename-pdf 316 B

123456789101112131415
  1. #!/bin/sh
  2. if [ $# -lt 1 ] ; then
  3. echo "Usage: $0 PDF-NAME"
  4. exit 1
  5. fi
  6. OLD_NAME=$1
  7. FILE_SLUG=$(pdfinfo $OLD_NAME | grep Title | cut -d: -f 2 | sed 's/ *$//g' | sed 's/^ *//g' | tr 'A-Z' 'a-z' | tr ' ' '-')
  8. if [ ! -z $FILE_SLUG ] ; then
  9. mv $OLD_NAME ${FILE_SLUG}.pdf
  10. else
  11. echo Cannot detect title
  12. fi