Recover From Broken References to Edited Files

If referenced masters are edited outside of Aperture without performing Open In External Editor and then the reference is broken, it may not be possible for Aperture to reconnect to the master, even by using the Referenced File Manager.

The reason for this is that to ensure the master being reconnected is the same image as the original, Aperture checks the file size. If editing changes the file size then the Reconnect button on the Referenced File manager will not be enabled.

Of course doing anything to masters behind Aperture's back like this is Bad News and is asking for trouble. To modify an image, whether referenced or managed, always use Open In External Editor, edit the image, save it (it goes into the library as a managed master), and then relocate the new master out of the library.

There are two ways out of this situation. The easy way is to delete the image with the broken reference (don't delete the referenced master!) and then reimport the master. This also loses all the adjustments and metadata, so may not be a suitable solution. The hard way, which I describe below, patches Aperture's library so that the file size information is correct and Aperture will reconnect the broken reference. This method does keep all the metadata and adjustments intact.

To allow Aperture to reconnect the master you have to correct the file size information that is in Aperture's database. To do that you have to get the correct file size, find and edit the image's apfile buried in the library, and then rebuild the database.

Find The Image apfile
Each master has an apfile, an XML file that describes the master. To find the apfile, inspect the image in Aperture and note its project, its location in the blue folder hierarchy, its import group, and its master file name. My example image is in the Tree Cutting project:
The inspector pane (I) shows the file name and the location of the master if it has been set up to do this:
Quit Aperture and navigate to your Aperture library in the Finder. Open the library using control-click Show Package Contents and navigate down into the library, through the blue folder hierarchy, and to the project folder:
Control click the project and Show Package Contents, then navigate to the image folder inside the project via the import group folder.
There it is: Pine tree chopping24.JPG.apfile

Find the correct file size for the image master
Open the Terminal application and type "ls -l " (that is lower case L, lowercase S, space, hyphen, lowercase L, space). Locate the image file in the finder and drag the image file icon onto the terminal window and let go:
Press Return and note the number displayed before the date. That is the correct file size in bytes:
In this case the number is 2128603. The Finder will show a larger file size because it includes space used by the resource fork:
Correct the file size in the apfile
Open the apfile using a text editor or XML editor (drag and drop the file onto the application icon of a text editor like TextWrangler in the dock). Locate the item fileSize and replace the size with the size you determined using the terminal above.
Close and save the apfile.

Repeat this for each of the images you need to recover and then close the library and project packages.

Rebuild the Aperture database
Locate the Aperture application icon and option-command double-click. Choose to rebuild the database and wait for it to complete.

Once done, the images that had their sizes fixed should be reconnectable.
The Bagelturf site welcomes Donations of any size