Skip to content

Instantly share code, notes, and snippets.

@stekhn
Last active December 8, 2017 15:59
Show Gist options
  • Save stekhn/05fe82c6316fb3bee8ec503bbf5a306e to your computer and use it in GitHub Desktop.
Save stekhn/05fe82c6316fb3bee8ec503bbf5a306e to your computer and use it in GitHub Desktop.
Bash script to count the total number of pages of multiple PDFs in a folder.
#!/bin/bash
sum=0
if [ "$1" != "" ]
then
dir=$1
else
dir=.
fi
for file in "$dir"/*.pdf
do
pages=$(mdls -raw -name kMDItemNumberOfPages "$file")
sum=$(($sum+$pages))
done
echo $sum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment