使用photos.app和applescript每小时上传随机文件

时间:2015-08-30 08:19:49

标签: macos upload applescript photos automator

我在一个文件夹中有宝贝照片,我希望每隔一小时(4000秒而不是3600秒)将它们一次上传到我所有亲戚在他们的iPhone和iPad和Mac上看到的共享iCloud专辑。这是我的AppleScript保存为应用程序并保持打开框检查。我认为这不太对劲。怎么了?

on idle

set importFolder to "Amac:Users:AbuDavid:Downloads:uploadBABY"
set extensionsList to {"jpg", "png", "tiff"}

tell application "Finder" to set theFiles to some file of importFolder whose name extension is in extensionsList

if (count of theFiles) < 1 then
    display dialog "No images selected!" buttons "OK"
else
    set albumName to "BabyDouDou"
    set timeNow to time string of (current date)
    set today to date string of (current date)
    set albumName to albumName & " " & timeNow & " " & today
    set imageList to theFiles

    tell application "Photos"
        activate
        delay 2
        import imageList into albumName skip check duplicates yes
    end tell

    tell application "Finder" to move theFiles to trash
end if
return 4000


end idle

2 个答案:

答案 0 :(得分:1)

有一些问题:

  • Finder需要关键字folder - 而不仅仅是文字字符串 - 来指定文件夹。
  • some file总是返回一个文件,因此count命令失败并始终返回0.
  • albumName也是一个文字字符串,而不是对象说明符。
  • Photos.app期望导入文件的alias说明符,而不是Finder对象说明符。

试试这个

on idle
  set importFolder to (path to downloads folder as text) & "uploadBABY"
  set extensionsList to {"jpg", "png", "tiff"}

  tell application "Finder" to set theFiles to files of folder importFolder whose name extension is in extensionsList

  if (count theFiles) < 1 then
      display dialog "No images selected!" buttons "OK"
  else
      set theFile to some item of theFiles
      set albumName to "BabyDouDou"
      set timeNow to time string of (current date)
      set today to date string of (current date)
      set albumName to albumName & " " & timeNow & " " & today
      set imageList to {theFile as alias}

      tell application "Photos"
          activate
          delay 2
          if not (exists container albumName) then
              set theAlbum to make new album
              set name of theAlbum to albumName
          else
              set theAlbum to container albumName
          end if
          import imageList into theAlbum skip check duplicates yes
      end tell

      tell application "Finder" to move theFiles to trash
  end if
  return 4000
end idle

答案 1 :(得分:1)

进行了一些小改动,仅删除上传的图像,而不删除所有图像。非常感谢你。

闲置     将importFolder设置为(以文本形式下载文件夹的路径)&amp; &#34; uploadBABY&#34;     将extensionsList设置为{&#34; jpg&#34;,&#34; png&#34;,&#34; tiff&#34;}

L.mapbox.map