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

Macos 使用photos.app和applescript每小时上传一次随机文件,macos,upload,applescript,photos,automator,Macos,Upload,Applescript,Photos,Automator,我的文件夹里有婴儿照片,我想大约每小时(4000秒而不是3600秒)上传一张到一个共享的iCloud相册中,我所有的亲戚都可以在他们的iPhone、iPad和Mac上看到。这是我的applescript保存为应用程序,并选中了“保持打开”框。我认为这不太正确。怎么了 on idle set importFolder to "Amac:Users:AbuDavid:Downloads:uploadBABY" set extensionsList to {"jpg", "png", "tiff"}

我的文件夹里有婴儿照片,我想大约每小时(4000秒而不是3600秒)上传一张到一个共享的iCloud相册中,我所有的亲戚都可以在他们的iPhone、iPad和Mac上看到。这是我的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
处于空闲状态
将importFolder设置为“Amac:Users:AbuDavid:Downloads:uploadBABY”
将extensionsList设置为{“jpg”、“png”、“tiff”}
告诉应用程序“Finder”将文件设置为某个名称扩展名在extensionsList中的importFolder文件
若(文件数)<1,那个么
显示对话框“未选择图像!”按钮“确定”
其他的
将albumName设置为“BabyDouDou”
将timeNow设置为的时间字符串(当前日期)
设置今天到日期字符串(当前日期)
将albumName设置为albumName&''&timeNow&''&today
将imageList设置为文件
告诉应用程序“照片”
激活
延迟2
将imageList导入albumName跳过检查重复项是
结束语
告诉应用程序“Finder”将文件移到垃圾箱
如果结束
返回4000
结束空闲
有一些问题:

  • 查找程序需要关键字
    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
处于空闲状态
将importFolder设置为(下载文件夹的路径为文本)和“uploadBABY”
将extensionsList设置为{“jpg”、“png”、“tiff”}
告诉应用程序“Finder”将文件设置为文件夹importFolder的文件,其扩展名在extensionsList中
若(计数文件)<1,则
显示对话框“未选择图像!”按钮“确定”
其他的
将文件设置为文件中的某些项
将albumName设置为“BabyDouDou”
将timeNow设置为的时间字符串(当前日期)
设置今天到日期字符串(当前日期)
将albumName设置为albumName&''&timeNow&''&today
将imageList设置为{theFile as alias}
告诉应用程序“照片”
激活
延迟2
如果不存在(存在容器名称),则
设置album以制作新相册
将album的名称设置为albumName
其他的
将album设置为容器album名称
如果结束
将图像列表导入album跳过检查重复项是
结束语
告诉应用程序“Finder”将文件移到垃圾箱
如果结束
返回4000
结束空闲

做了一个小改动,只删除上传的图像,而不是所有图像。非常感谢你

闲置 将importFolder设置为(下载文件夹的路径为文本)和“uploadBABY” 将extensionsList设置为{“jpg”、“png”、“tiff”}

告诉应用程序“Finder”将文件设置为文件夹importFolder的文件,其扩展名在extensionsList中
若(计数文件)<1,则
显示对话框“未选择图像!”按钮“确定”
其他的
将文件设置为文件中的某些项
将albumName设置为“testscript”
将imageList设置为{theFile as alias}
告诉应用程序“照片”
激活
延迟2
如果不存在(存在容器名称),则
设置album以制作新相册
将album的名称设置为albumName
其他的
将album设置为容器album名称
如果结束
将图像列表导入album跳过检查重复项是
结束语
告诉应用程序“Finder”将文件移到垃圾箱
如果结束
返回7
结束空闲
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 "testscript"
    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 theFile to trash
end if
return 7
end idle