Skip to content

Instantly share code, notes, and snippets.

@dipnlik
Forked from metalrufflez/wallpaper_organizer.sh
Created December 10, 2012 20:50
Show Gist options
  • Save dipnlik/4253291 to your computer and use it in GitHub Desktop.
Save dipnlik/4253291 to your computer and use it in GitHub Desktop.
Organize wallpapers according to aspect ratio
#!/bin/bash
shopt -s nullglob # won't error if a glob has no match
wallpaper_dir="$HOME/Dropbox/Photos/Wallpapers"
cd $wallpaper_dir
files=(*jpg *jpeg *png *bmp)
for file in "${files[@]}"
do read -r width height <<< $(sips -g pixelWidth -g pixelHeight "$file" | awk '/pixel(Width|Height)/ {print $2}')
# Check if the file is a valid image, if not skip
[ -z "$width" ] && continue
# Test the ratio against my pre configured ones
case $(echo "scale=3;$width / $height" | bc) in
1.333) ratio="4:3" ;;
1.250) ratio="5:4" ;;
1.777) ratio="16:9" ;;
1.600) ratio="16:10" ;;
*) ratio="other_ratio" ;;
esac
echo "Moving $file to $ratio"
mv "$file" "$wallpaper_dir/${ratio/:/x}/"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment