I edit RAW photos in Photoshop using Adobe Camera Raw. The way the edits work is any time I work on a picture, Photoshop creates a text file with the same name as the picture to which the edits were made. However, sometimes when I delete an image, or use it in a Photomerge, the XML file stays behind. Thus I now have a folder with ~1100 RAW images (.NEF), ~1300 text files (.xmp) and a few photoshop files (.psd, .psb).

I would like to parse this folder, using either AppleScript or a bash command, and either mark or delete the .xmp files that do not have a companion RAW file. Logically, the code would be: for every .xmp file, check for a .NEF file with same name. If .NEF does not exist, delete or mark the .xmp file. If .NEF does exist, do nothing.

I am not familiar with AppleScript, and although I am familiar with ffmpeg, diskutil, and basic cd/ls and rsync commands in terminal, I have never attempted something like this and do not know where to start.

So, I was hoping someone on here could:

  1. Help decide whether bash or AppleScript is more appropriate here AND
  2. Help me write the sequence OR point me to some good resources where I could learn enough (either bash or AppleScript) to write the sequence myself.
  • Comments are not for extended discussion; this conversation has been moved to chat.
    – nohillside
    Apr 17, 2017 at 15:11

1 Answer 1


In Terminal, change directory, e.g. cd /path/to/files, to the location of the target files and then use the following command to delete any .xmp file that doesn't have a corresponding .NEF file:

for f in *.xmp; do [[ ! -f ${f%.*}.NEF ]] && rm "$f"; done
  • This works perfectly! That's so much easier than I thought it would be!
    – NoahL
    Apr 16, 2017 at 19:57
  • 1
    Wouldn't "${f%.*}.xmp" be the same a "$f"?
    – fd0
    Apr 17, 2017 at 14:40
  • 1
    @fd0, In this case, yes it's the same and of course works either way. I posted this before having had coffee and was being lazy by copying and pasting changing ${f%.*}.NEF to "${f%.*}.xmp". I've shortened it now. Apr 17, 2017 at 14:56
  • @user3439894 Extra points for a good use of lazy execution. Apr 18, 2017 at 1:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .