const photos = Application('photos');
const albums = photos.albums();

albums.forEach(album => {
  const name = album.name();
  const items = album.mediaItems();
  const path = Path('./export/' + name);
  items.forEach(item => {
    const filename = item.filename();
    console.log(filename + ' => ' + path + '/'  + filename);
    photos.export([item], {to: path});
  });
});

@@ -41,330 +41,1205 @@
 nst 
-albums = photos.albums();%0A%0Aalbums.forEach(album =%3E %7B%0A  const name = album.name();%0A  const items = album.mediaItems();%0A  const path = Path('./export/' + name);%0A  items.forEach(item =%3E %7B%0A    const filename = item.filename();%0A    console.log(filename + ' =%3E ' + path + '/'  + filename);%0A    photos.export(%5Bitem%5D, %7Bto: path%7D);
+terminal = Application('terminal');%0Aconst albums = photos.albums();%0A%0Aconst pad = (val) =%3E String(val).length %3C 2 ? '0' + val : String(val);%0Aconst app = Application.currentApplication()%0Aapp.includeStandardAdditions = true;%0A%0Aalbums.forEach(album =%3E %7B%0A  const name = album.name();%0A  const items = album.mediaItems();%0A  const path = Path('./export/' + name);%0A%0A  // Export items one by one to prevent timeout%0A  // Set creation data becausse photos might not set them for videos%0A  items.forEach(item =%3E %7B%0A    const filename = item.filename();%0A    const date = item.date();%0A    const formattedDate = pad(date.getMonth() + 1) + '/' +%0A      pad(date.getDate()) + '/' +%0A      date.getFullYear() + ' ' +%0A      pad(date.getHours()) + ':' +%0A      pad(date.getMinutes()) + ':' +%0A      pad(date.getSeconds());%0A%0A    console.log(filename + ' =%3E ' + path);%0A    photos.export(%5Bitem%5D, %7Bto: path%7D);%0A%0A    const videoPath = (path + '/' + filename).replace(/(.*)%5C.%5B0-9A-Za-z%5D+$/, '$1.m4v');%0A    const cmd = 'ls %22' + videoPath + '%22 && ' +%0A      'SetFile -d %22' + formattedDate + '%22 %22' + videoPath + '%22';%0A%0A    try %7B%0A      app.doShellScript(cmd);%0A      console.log('Set creation date for video file');%0A    %7D catch (e) %7B%0A    %7D
 %0A  %7D

Set creation date for videos