6V8 - Production of my Mind

Home page > For your Computer > Automator > Move/Rename files according to metadata (EXIF, ID3, ...)

Move/Rename files according to metadata (EXIF, ID3, ...)

 

This is an Automator action (for Apple Automator.app) that takes a list of files as input and will move them according to a special pattern which can use the metadata fields of the file.

You will be able to move images according to their EXIF data (date taken, camera model, ...), move audio files according to their ID3 tags (artist, title, ...), move PDF files according to their author, etc... etc...

Automator Action | 2 September 2007, by Mortimer

1 Principle

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.

1.1 Example of moving photos

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.

PNG - 23.2 kb
Example Results

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: %Y/%m/%d/

The action will extract information from the EXIF data and replace the special markers in the pattern:

  • %Y will be replaced by the year
  • %m will be replaced by the month
  • %d will 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.

2 Installation

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) [1].

Zip - 1 Mb
MetaDataMover download
2029 download(s) since 21 November 2008

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) [2].

3 Using the Action

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: %Y/%m/%d/,
  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 5.3.

4 Special Patterns Elements

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 5.3) counter if a file with the same name already exists, otherwise, it will just be removed.

5 Detailed Behaviour

Here are the specifics on how the action deals with the different possible cases.

5.1 Trailing Slash

If the path pattern finishes with a /, then it is taken as the directory where the file should be moved, without being renamed.

5.2 File Renaming

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.

5.3 File Clash avoiding

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.

6 Introduction to Photo meta data

 

6.1 EXIF Date Patterns

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:

Useful time/date formating
Pattern Meaning
%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).
%S seconds
%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.

6.2 EXIF Patterns Elements

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.

Useful EXIF fields
FieldMeaning
:Model: the name of the camera model
:Manufacturer: the camera brand
:ISO:the iso setting
:FNumber: the aperture in f value

7 Introduction to Music files meta data

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.

Useful ID3 fields
FieldMeaning
:Artist: the performing artist
:Album: the album of this track
:Title:the title of this track
:Genre: the genre classification of this track

8 Organising PDF Documents

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...

Useful PDF fields
FieldMeaning
:Title: the document title
:Creator: the document creator
:Author:the document author

9 Other file formats supported

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:


10 Development and Localisation

You can get the development version of this action from the repo git repository.

If you want to propose a path, first clone the repository on your local drive:


git clone git://repo.or.cz/AutomatorExifMover.git

make modifications, commit them to your local repository and format a patch for emailling to me with:


git-format-patch

The script is already localised in French, Italian and English. If you want to propose a new localisation, contact me.

Changelog

15 February 2008

    • update version of ExifTool to 7.18

13 February 2008 first update

    • allow - in path pattern and tag values. This was previously replaced by _,
    • trim blank spaces around tag values,
    • use file creation/modification date if there is no other data information in the meta data,
    • some little optimizations,
    • replace / in tag names with _.
Date of online publication: 2 September 2007
last-update: 21 November 2008
Forum messages 62
visits:
45423

Some Right Reserved: Distributed under the terms of the GNU General Public License.

notes

[1] Create the directory if needed.

[2] Create the directory if needed.

Make a Donation

1 user(s) already donated a total of 2.5£ to this project.

Donation don't have to be big to make a difference. I already received donations ranging from 0.50£ to 10£ and all of them made me happy. Think of it, if the thousand users of these tools made a small donation, it would not make a big difference to them, but it would to me.

You will probably enjoy using what you download from this website and if so, you can decide to make a donation. Making a donation is optional but will help to develop new tools and support the existing code.

All the software, scripts and other tools distributed on this web site are distributed under open source licenses and are available to download for free. Making the code free and available to all doesn't means it's of lower quality. The tools provided here are fully functional and their author invested some of his personal time to develop them and provide support to their users.

Think about it.

 

P.S.

If you want to use exiftool configuration file for custom tags, etc. Place the .ExifTool_config file in your $HOME directory.

Reply to this article

62 Forum messages

 

The most read articles

 
©
Pierre Andrews
York, uk
| Site Map | Site created with SPIP 1.9.2c [10268] | RSS | template by IZO, Mortimer. | clicky stats
tiramisu created Tina tiramisu created
tiramisu created Tina tiramisu created
tiramisu created Tina tiramisu created
tiramisu created Tina tiramisu created
tiramisu created Tina tiramisu created