我正在尝试创建一个脚本,用于在Yosemite的照片中将目录导入为专辑。
activate application "SystemUIServer"
tell application "Finder"
activate
repeat with flder in (get selection as alias list)
set albumName to name of flder
tell application "Photos"
make new album named albumName
set imageList to {}
repeat with i from 1 to number of items in flder
set this_item to item i of flder as alias
set the end of imageList to this_item
end repeat
import imageList into album albumName
end tell
end repeat
end tell
根据我发现的情况,这应该有用 - 它没有:
error "Photos got an error:
Can’t make alias \"Macintosh HD:Users:knyttl:Pictures:archive:2014:01_prom:\" into type specifier." number -1700
from alias "Macintosh HD:Users:knyttl:Pictures:archive:2014:01_prom:" to specifier
它符合number
部分中的repeat
。我甚至不确定语法是否正确 - 在某些地方我看到number
在其他一些count
上,在其他一些地方,迭代文件是以完全不同的方式完成的。我会很高兴得到任何帮助。
答案 0 :(得分:1)
主要问题是收集文件夹中实际为Photos
术语的项目时Finder
tell块中的术语冲突。
试试这个,我将应用程序告诉块分别仅扭曲了特定的术语。
activate application "SystemUIServer"
tell application "Finder" to set folderList to selection
repeat with aFolder in folderList
set albumName to name of aFolder
tell application "Photos" to set newAlbum to make new album named albumName
set imageList to {}
repeat with i from 1 to number of items in aFolder
set this_item to item i of aFolder as alias
set the end of imageList to this_item
end repeat
tell application "Photos" to import imageList into newAlbum
end repeat
或更容易
activate application "SystemUIServer"
tell application "Finder" to set folderList to selection
repeat with aFolder in folderList
tell application "Finder"
set albumName to name of aFolder
set imageList to files of aFolder as alias list
end tell
tell application "Photos"
set newAlbum to make new album named albumName
import imageList into newAlbum
end tell
end repeat
答案 1 :(得分:1)
同意,这似乎是分离照片和Finder tell
块的问题。
以下是我的工作,一次用多个文件夹进行测试:
tell application "Finder"
activate
repeat with flder in (get selection)
set albumName to name of flder
set imageList to {}
repeat with i from 1 to (count of items of flder)
set photo to item i of flder
set the end of imageList to photo as alias
end repeat
tell application "Photos"
set newAlbum to make new album named albumName
import imageList into newAlbum
end tell
end repeat
end tell