我试图从iPhotos和照片应用中获取所有照片。 我发现这个脚本可以导出iPhotos中的所有图片。但是,当我将其更改为使用“照片”应用时,它无法正常工作。
set destination to quoted form of POSIX path of (path to pictures folder)
tell application "iPhoto"
repeat with i in (get selection)
tell i to my copyPhoto(date, image path, title, destination)
end repeat
end tell
on copyPhoto(d, p, t, dest) -- the name of the file is the title of the photo in iPhoto, date format for folder name = 2014-09-25
tell d to set d to "" & its year & "-" & text -2 thru -1 of ("0" & ((its month) as integer)) & "-" & text -2 thru -1 of ("0" & its day)
try -- create folder if neccessary, check to not overwrite any files in the subfolder, copy the file, rename with the title
do shell script "f=" & d & ";t=" & (quoted form of t) & ";tFile=" & (quoted form of p) & "; e=${tFile##*.}; cd " & dest & ";mkdir -p \"$f\"; while [ -e \"$f/$t.$e\" ];do t=\"$t _\";done; cp -a \"$tFile\" \"$f/$t.$e\""
end try
end copyPhoto
(来自https://discussions.apple.com/thread/6565154?start=0&tstart=0)
是否有人能够帮助我弄清楚如何使用照片应用进行此操作? 脚本使用它的格式完美,图片由文件夹组织:
2014年12月30日
2015年1月1日
2015年1月2日
...
感谢!!!!
答案 0 :(得分:1)
Vadian是对的,没有"图像路径"在照片中(感谢Apple!),所以必须使用Export。请参阅下面的脚本bello,如果需要,还可以格式化日期和创建文件夹。
set TopFolder to (path to desktop folder from user domain) as string -- your main destination folder
tell application "Photos"
repeat with aPhoto in (get selection)
set SName to filename of aPhoto
set theDate to date of aPhoto
-- convert date to string yyyy-mm-dd
set SY to (year of theDate) as string
set SM to text -2 thru -1 of ("0" & ((month of theDate) as integer))
set SD to text -2 thru -1 of ("0" & ((day of theDate) as string))
set DestFolder to SY & "-" & SM & "-" & SD -- DestFolder = folder "date"
-- check if folder DestFolder exists : if not creation
tell application "Finder"
if not (folder (TopFolder & DestFolder) exists) then
make new folder in TopFolder with properties {name:DestFolder}
end if
end tell
-- you may have to add a check if file (TopFolder & DestFolder & SName) already exists
-- and take appropriate action (add index, add word "copy",...)
export {aPhoto} to (TopFolder & DestFolder)
end repeat
end tell
在测试期间,我发现照片比iPhoto慢得多。只是为了得到日期或文件名属性需要时间!还"出口"确实。脚本本身可以使用shell函数优化日期格式化或文件夹检查/创建(我不是shell专家),但速度瓶颈仍然是照片!