This is an action for Mac OS X Automator that takes a special path pattern and will try to rename the files it get in inputs according to that pattern.
We call it a "path pattern" because it can contain elements that will be replaced for each file with information coming for the meta data stored in the file.
Let's make an example. The script supports the EXIF meta data field included in photo files by your camera. It can therefore use them to move the images.
Let's say you have a bunch of images that you would want to move in directories named from the date they were taken at, like:
2007 08 12 IMG_1.jpg IMG_2.jpg 07 25 IMG_3.jpg 2006 01 28 IMG_4.jpg
You can set the path pattern parameter of the Automator action with the pattern:
The action will extract information from the EXIF data and replace the special markers in the pattern:
%Ywill be replaced by the year
%mwill be replaced by the month
%dwill be replaced by the day
the directory structure will be created and the file moved in the right directory.
There is more detail later on how the patterns work, but this is the basic idea.
Download and open the following disk image.
Check out the license and move the MetaDataMove.action file in the directory ~/Library/Automator/ (for a particular user) or /Library/Automator/ (for all users)
Extract the archive and inside you will find MetaDataMover.action, move this file in the directory ~/Library/Automator/ (for a particular user) or /Library/Automator/ (for all users)
Once installed, you will find the action in Automator under the Finder application. Just drag and drop it in the workflow just after an action that returns a list of files.
The action will return a list of the moved/renamed files.
Here are the option:
1- do you wish to copy or move the files, default is copy,
2- what path pattern should be used. This is the pattern for the moving/renaming of the file. The default is for EXIF patterns:
3- in which root directory to put the new files. The path pattern will be applied from that directory. The default is the directory where the current file is,
4- you can check this option and follow the action by the "View Results" action from Automator to do a test run,
5- you can check this option if you are OK with the action overwriting existing file. The default is to not overwrite existing files, see clash.
Most of the pattern -- except for the date notation in the EXIF case -- elements follow a simple notation, they are the name of a field in the file metadata with columns (':') around. You can use more than once the same marker in the pattern if you wish.
The available meta data fields change according to the file type you are passing to the action. The main fields for photos, music files and PDF are discussed later. Generally, the action uses ExifTool by Phil Harvey and therefore, the fields read by this tool can be used, for more details, please see ExifTool tag names documentation.
The action also offers some basic pattern elements:
:basename:is the name of the file, without extensions,
:ext:is the extension of the file, with the period (
:cnt:will be replaced by the clash avoidance (see clash) counter if a file with the same name already exists, otherwise, it will just be removed.
Here are the specifics on how the action deals with the different possible cases.
If the path pattern finishes with a
/, then it is taken as the directory where the file should be moved, without being renamed.
If the path pattern doesn't finish with a
/, the last part of the path is supposed to be the renaming pattern for the file. If it doesn't contain an extension (. followed by something), then the extension of the original file will be used.
If the option overwrite is not checked, the action will avoid replacing an existing file with a file it is renaming. The action has two choices then:
- if the path pattern you specified uses the
:cnt:special marker, it will replace this by a counter.
- otherwise, the action will add a counter at the end of the file name, just before the file extension. The action will start with the counter at 1 and try to write the file, if a file with the same counter already exist, it will increment the counter until it finds a new file name.
The photo files containing EXIF metadata can use another special notation to extract the date when the photo was taken (as described in the previous example). The date pattern format is the one provided by the strftime tool. Check out its man page for details. Here are useful fields:
|%d||The day of the month as a decimal number (range 01 to 31).|
|%H||The hour as a decimal number using a 24-hour clock (range 00 to 23).|
|%I||The hour as a decimal number using a 12-hour clock (range 01 to 12).|
|%m||The month as a decimal number (range 01 to 12).|
|%M||The minute as a decimal number (range 00 to 59).|
|%s||The number of seconds since the Epoch, i.e., since 1970-01-01 00:00:00 UTC.|
|%u||The day of the week as a decimal, range 1 to 7, Monday being 1.|
|%y||The year as a decimal number without a century (range 00 to 99).|
|%Y||The year as a decimal number including the century.|
You can also tell the tool to extract other EXIF information by putting the EXIF field name between columns (
:) in the pattern. For example,
%Y/%m/%d/:Model:/ will put the photos in subdirectories by date and then by model of camera.
|:Model:||the name of the camera model|
|:Manufacturer:||the camera brand|
|:ISO:||the iso setting|
|:FNumber:||the aperture in f value|
Most of the modern music file formats like mp3 support meta data fields to store the name of the track, the performing artist, etc... The action can extract these fields and can be used to organise a music collection automatically.
|:Artist:||the performing artist|
|:Album:||the album of this track|
|:Title:||the title of this track|
|:Genre:||the genre classification of this track|
You can also use the automator action to organise your pdf documents if they contain the right metadata. If the author of the file has tagged it with the right information, you can extract his name, etc... etc...
|:Title:||the document title|
|:Creator:||the document creator|
|:Author:||the document author|
This automator action is based on the great ExifTool library. It will support all metadata format supported by that library. For details on each format and the tags availlable for that format, see the exiftool tag names documentation page or go directly to the format you are interested in from this list:
The script is already localised in French, Italian and English. If you want to propose a new localisation, contact me.
This code uses ExifTool by Phil Harvey for all the metadata extraction: http://www.sno.phy.queensu.ca/~phil/exiftool/
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.