Skip to content

Instantly share code, notes, and snippets.

@ddikman
Created May 3, 2018 03:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ddikman/a23d98e84c940a21193837ad0303fc1c to your computer and use it in GitHub Desktop.
Save ddikman/a23d98e84c940a21193837ad0303fc1c to your computer and use it in GitHub Desktop.
Helper to offset timezone of files in OSX.
#!/bin/bash
# Helper to modify a file modification date in case timezone is wrong.
# I noticed that when moving files from my camera whilst travelling the time zone was off and needed to bulk adjust them.
# Written and tested on osx bash, in GNU this script is superfluous since touch can do a relative -d '-2 hours' flag which osx shell doesn't support..
set -euo pipefail
SCRIPT_NAME=`basename "$0"`
# helper to log to stderr
function log() {
>&2 echo "${1}"
}
if [[ "$#" -ne 2 ]]; then
log "Invalid arguments."
log "Usage: ${SCRIPT_NAME} <offset hours> <filename>"
log "Example: ${SCRIPT_NAME} -2 P5012.jpg"
exit 1
fi
MODIFY_HOURS=$1
MODIFY_FILE=$2
FILE_EPOCH_TIME=`stat -f "%Sm" -t %s ${MODIFY_FILE}`
MODIFIED_TIME=`date -v "${MODIFY_HOURS}H" -j -f %s ${FILE_EPOCH_TIME} "+%y%m%d%H%M"`
touch -mt ${MODIFIED_TIME} "${MODIFY_FILE}"
log "done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment