2015-08-30 44 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 

相關問題