2015-08-30 22 views
0

我在一个文件夹中有婴儿照片,我想每隔一小时(4000秒3600秒)一次上传它们到共享的iCloud专辑中,我的所有亲戚都会看到在他们的iPhone,iPad和Mac上。这是我的applescript保存为一个应用程序与保持打开框中检查。我认为这不太合适。怎么了?用photos.app和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 

回答

1

有一些问题:

  • 取景器所需要的关键字folder - 不只是文字字符串 - 到指定的文件夹。
  • 总是返回一个文件,因此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

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

上空闲 集importFolder至(路径下载文件夹作为文本)& “uploadBABY” 组extensionsList为{ “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 "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 

相关问题