title: Bash shell script to modify the images' date created by reading the creation date from XMP file
body: <p>Story: I am currently using Apple's Photos app to store my photos. But I found that when I export the photos, their dates created are not the same as their original taken date. Therefore, I want to batch modify the date created by the XMP file generated from the Photos App:</p>
  <pre><code>    #!/bin/bash
      IFS='
      '
      dir=&quot;./Home&quot;
      find $dir -type f -print0 | while read -d $'\0' x
      do
        fullNoExt=${x%.*}
        filenameNoExt=${fullNoExt##*/}
        fullImgPath=$(find ./Home -not -name &quot;$filenameNoExt.xmp&quot; -name &quot;$filenameNoExt.*&quot;)
        fullXMPPath=&quot;$fullNoExt.xmp&quot;
        while IFS= read -r line
        do
          title=$(perl -ne 'print and last if s/.*&lt;photoshop:DateCreated&gt;(.*)&lt;\/photoshop:DateCreated&gt;.*/\1/;' &lt;&lt;&lt;  &quot;$line&quot;)
          if [[ &quot;$title&quot; == &quot;&quot; ]]
          then
            continue
          else
            ymd=$(echo &quot;$title&quot;| awk '{ print substr($0,1,4)substr($0,6,2)substr($0,9,2)substr($0,12,2)substr($0,15,2) }')
            touch -t $ymd $fullImgPath
          fi
      
        done &lt; &quot;$fullXMPPath&quot;
      done
  </code></pre>
  <p>Would anyone comment on or enhance my piece of work :)</p>