Skip to content

Instantly share code, notes, and snippets.

@bndw
Last active July 22, 2018 22:05
Show Gist options
  • Save bndw/c5f113f96986d67caebcdf382bb51447 to your computer and use it in GitHub Desktop.
Save bndw/c5f113f96986d67caebcdf382bb51447 to your computer and use it in GitHub Desktop.
A script for importing photos from an SD card to a local directory
#!/bin/bash
#
# This script is used to copy images files from a connected volume to a local
# directory.
#
# - Creates a folder with today's date in $PHOTO_DIR
# - Moves RAW files into the root $PHOTO_DIR
# - Creates a folder for JPEG images
# - Creates a folder for edits/exports
# - Creates a README file
# Example folder layout:
#
# /Users/bdw/Pictures/20180722/
# ├── DSCF0266.RAF
# ├── DSCF0267.RAF
# ├── DSCF0268.RAF
# ├── README.md
# ├── _edits
# └── _jpeg
# ├── DSCF0266.JPG
# ├── DSCF0267.JPG
# ├── DSCF0268.JPG
#
set -e
# Configuration
IMPORT_DEVICE=/Volumes/Untitled
PHOTO_DIR=/Users/bdw/Pictures
COPY_OR_MOVE_FILES=mv
DATE_FMT="+%Y%m%d"
EDITOR=vi
DATE=$(date "${DATE_FMT}")
IMPORT_DIR="${PHOTO_DIR}/${DATE}"
JPEG_DIR="${IMPORT_DIR}/_jpeg"
EDITS_DIR="${IMPORT_DIR}/_edits"
README="${IMPORT_DIR}/README.md"
# 1. Setup folder structure
if [ ! -d "${IMPORT_DIR}" ]; then
mkdir "${IMPORT_DIR}" && cat <<EOF > ${README}
# ${DATE}
* Location:
* Description:
EOF
sleep .2
fi
if [ ! -d "${JPEG_DIR}" ]; then mkdir "${JPEG_DIR}"; fi
if [ ! -d "${EDITS_DIR}" ]; then mkdir "${EDITS_DIR}"; fi
# 2. Fill out the README with description, etc
"${EDITOR}" "${README}"
# 3. Copy or move the photos
import_raw() {
find "${IMPORT_DEVICE}/DCIM" -name "*.RAF" -type f -exec "${COPY_OR_MOVE_FILES}" {} "${IMPORT_DIR}" \;
}
import_jpg() {
find "${IMPORT_DEVICE}/DCIM" -name "*.JPG" -type f -exec "${COPY_OR_MOVE_FILES}" {} "${JPEG_DIR}" \;
}
import_jpg && import_raw
echo "${IMPORT_DIR}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment