Creating a Conversion Action

A conversion action acts as a kind of bridge between two actions whose types of provided data (AMProvides property) and accepted data (AMAccepts) do not match. The conversion action converts between one type and another, usually from an internally defined data type (such as an iTunes track object, specified by the UTI identifier com.apple.itunes.track-object) to an externally defined public type (such as a file, specified by public.item).

Automator does not display conversion actions and users do not have to bother placing them between actions. The application determines if there is a data-type mismatch between two actions and, if a suitable conversion action is available, it inserts it invisibly between them. Conversion actions have a bundle extension of .caction and are installed in the usual system directories for actions.

You create a conversion action just as you would a “normal” action (as described in “Developing an Action”) but with just a few differences:

Listing 1  Typical Automator properties for conversion actions

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>AMAccepts</key>
    <dict>
        <key>Container</key>
        <string>List</string>
        <key>Types</key>
        <array>
            <string>com.apple.iphoto.photo-object</string>
        </array>
    </dict>
    <key>AMApplication</key>
    <string>Automator</string>
    <key>AMCategory</key>
    <string>Converter/Filter</string>
    <key>AMDefaultParameters</key>
    <dict/>
    <key>AMIconName</key>
    <string>(* The name of the icon *)</string>
    <key>AMName</key>
    <string>Convert Photo object to Alias object</string>
    <key>AMProvides</key>
    <dict>
        <key>Container</key>
        <string>List</string>
        <key>Types</key>
        <array>
            <string>public.item</string>
        </array>
    </dict>
    <!- other properties here -->
</dict>
</plist>

As the final step, write the script or Objective-C source code to do the conversion. The script example in Figure 1 converts iPhoto objects representing photo images to paths to those images in the file system.

Figure 1  A typical conversion script
A typical conversion script