Monday, November 5, 2012

Batch renaming photos using exiftool

I have a bunch of photos with random names in a folder. I would like to batch rename them to a "year month day hour minute second" format. Inside the directory:
exiftool '-filename<DateTimeOriginal' -d %y%m%d_%H%M%S%%-c.%%le *jpg
The DateTimeOriginal tag comes from the exif data. The -d option is for the date format. In particular here we put the %%-c in the end of the date so increasing numbers are added in the end of the file name of photos taken at the very same time. ".%%le" stands for "dot and lower case extension".

If the camera time was reset back then and we somehow find out that there is an offset of  5 years, 1 month, 30 days, 10 hours, 50 minutes and 3 seconds, then this will fix that:
exiftool "-DateTimeOriginal+=5:1:30 10:50:3" directory
where directory is the directory were the photos are stored.

Then one possibly needs to update the other exif date tags, like modification and creation dates. For that one has to use AllDates:
exiftool "-AllDates<DateTimeOriginal" directory
UPDATE: Actually correcting the dates may be much easier..
exiftool -alldates+=7 *.jpg
The line above will add 7 hours to all the date tags of all jpg images in the folder.

Sunday, November 6, 2011

Bash trick: last command shortcut

In bash, two consecutive exclamation marks (!!) stand for 'the previous command'. One instance where this could be particularly useful is when you forget the sudo command (happens to me often):
[jorge@flamingo media]$ mkdir test
mkdir: cannot create directory `test': Permission denied
(Ah, yes, I forgot the sudo!)
[jorge@flamingo media]$ sudo !!
sudo mkdir test
Password: 

Friday, November 4, 2011

Dropbox does not connect on startup

I have issues with Dropbox on my laptop running arch linux. If the internet connection is lost, uppon
reconnection Dropobox fails to reconnect and its status stays forever to "Connecting". I wrote a script
that checks if there is connection to the internet and if so, it restarts the dropbox service if hung. It has
to be run on startup in the background.

#!/bin/bash

# While there is a connection, the script checks every 60 secs if 
# the dropbox status is "Dropbox isn't running" or "Connecting",
# and if so, it reconnects the service. Could start from .xinitrc.

while true; do
    ping -c 1 www.google.com 1>/dev/null 2>/dev/null
    if [ "$?" = 0 ]; then
        dropbox status | egrep 'isn|Connecting'>/dev/null
        if [ "$?" = 0 ]; then
            dropbox stop
            dropbox start
        fi
     fi
    sleep 2
done

To make this work you have to run the above script on startup. For instance, you could do the following:
  • Put the above lines in a file called checkdropboxstatus.sh. 
  • Put that file in you /home/yourusername/.config/autostart/ folder.
  • Go to that folder and change the permissions to executable
    cd /home/yourusername/.config/autostart
    chmod +x checkdropbox.sh
Now dropbox shouldn't hung anymore.