Posts Tagged ‘scripting’
Need to quickly off-load photos from your camera and neatly organize them into folders by date? The Fotobasher shell script cobbled together by yours truly can help you with that.
The script copies photos from a mounted storage device like an SD card to the TMP directory, organizes the photos into folders by date, and then renames each photo using the data pulled from the photo’s metadata. Photos are renamed using the YYYYMMDD-HHMMSS-ShutterCount.EXT format, so the resulting file name looks something like this: 19730115-135547-3375.NEF. Fotobasher is configured to work with Nikon D90, but adapting the script to other camera models requires only a few simple tweaks.
If you have Git installed on your machine, you can clone the Fotobasher Git repository using the following command:
git clone git://github.com/dmpop/fotobasher.git
Alternatively, you can download the latest release of Fotobasher from the project’s download page.
To make Fotobasher work on your machine, you need to do some preparatory work. Start with installing the ExifTool utility which the script uses to extract relevant metadata, arrange photos, and rename them. ExifTool is available in the software repositories of many mainstream Linux distributions, so you can install it using your distro’s package manager. On Debian and Ubuntu, you can do this by executing the following command:
sudo apt-get install libimage-exiftool-perl
Next, make the fotobasher.sh script executable using the following command:
chmod +x fotobasher.sh
Rename then the ExifTool_config file to .ExifTool_config and move it to your home directory:
cp fotobasher/ExifTool_config ~/.ExifTool_config
Adding the .ExifTool_config file is required only if you want to include the shutter count value in the file names. In case you use another renaming rule, you can skip this step.
Finally, open the script in a text editor and specify the desired TARGET_DIR value and the correct file format (e.g., RAW, CR2, or JPG).
That’s all there is to it. Insert the card with photos, run the script to download the photos, arrange them into folders, and rename them.
One of digiKam’s lesser known features is the ability to link scripts to notifications. At first sight, this may seem like a rather obscure functionality, but it can be put to some clever uses. Say, you want to keep a portfolio of selected photos on a mobile device. Resizing multiple photos to a specified size to make it easier to view them on the mobile device and transferring the processed photos from digiKam to the mobile device manually is not very practical. And this is where the ability to trigger scripts via notifications can come in handy. You can attach a simple Bash script to the Batch queue completed notification, so it’s triggered automatically when the Batch Queue Manager tool is done processing photos.
The Bash script is very simple, indeed. It uses the rsync tool to copy the processed photos from the source directory (in this case, it’s /home/user/Photos/Processed) to the /DCIM/Camera directory on the mounted SD card:
rsync -avz --delete /home/user/Photos/Processed /media/0CFA-5602/DCIM/Camera
Paste the code above into an empty text file and save it as a postprocess.sh file (don’t forget to replace the example paths with the actual paths to the source and destination directories). Make then the script executable using the chmod o+x postprocess.sh command.
In digiKam, choose Settings » Configure Notifications and select the Batch queue completed item. Tick the Run command check box, and enter the path to the postprocess.sh script in the appropriate field. As you might have guessed, this links the script to the notification, so the script is triggered as soon as the batch operation is finished.
Next, create a tag (e.g., transfer) in digiKam and assign it to the photos you want to transfer to the mobile device. Alternatively, you can use a specific color label for that. Use then the Filter right sidebar to display the tagged or labelled photos, select them, and press Ctrl+B (or choose Tools » Batch Queue Manager) to add them to a new batch queue. In the Queue Settings section, click on the Target tab and select the Photos » Processede sub-album. Under the Base Tools tab, double-click on the Transform » Resize tool to add it to the Assigned Tools section. In the Tool Settings pane, specify the desired length. You can choose between several presets, or enable the Use Custom Length option and specify the desired length.
Hit then the Run button, and once the batch operation is completed, the assigned Bash script copies the resized photos to the mounted SD card.
You can tweak the script to perform other post-processing actions, too. For example, if you use the llgal command-line tool to generate static HTML photo galleries, you can tweak the script to add the processed photos to an HTML album. The script may look something like this:
llgal --exif --li -L --sx 800 --sy 600
In other words, you can do all kinds of clever tricks by linking scripts to notifications.