Applescript错误:无法将应用程序“照片”的类xxxx设置为类型列表,记录或文本

问题描述 投票:0回答:1

我很困惑,需要一些帮助来调试我编写的某些AppleScript。为了满足我的需要,我已将Apple Photos库导出到外部磁盘位置,并将每张照片的媒体项目ID写入文件中嵌入的元数据。这样,当外部文件的关键字更新时,我可以更新Apple Photos以反映这一点。这是相关的脚本:

tell application "Finder"
set theFile to "G-DRIVE:Media:photo:2015:12:2015-12-25_at_11h53m13s_DSC_0073.NEF" as alias

set fileString to my convertPathToPOSIXString(theFile)  
set photosID to do shell script "/usr/local/bin/exiftool -config /Volumes/G-DRIVE/Scratch/customConfig -if 'defined $JustinApplePhotosID' -s -s -s -xmp:JustinApplePhotosID " & "'" & fileString & "'"
end tell

tell application "Photos"
set updateItems to (get media items whose id is photosID)
set numItems to the number of updateItems
if the number of updateItems is equal to 1 then
    set mediaItem to the first item in updateItems
        set keywordResult to do shell script "/usr/local/bin/exiftool -s -s -s -keywords " & "'" & fileString & "'"
        set keywordArray to my theSplit(keywordResult, ",")
        set the keywords of mediaItem to keywordArray

        if keywordArray contains "5*****" and album "5 Stars" does not contain {mediaItem} then
            add {mediaItem} to album "5 Stars"
        else if keywordArray does not contain "5*****" and album "5 Stars" contains {mediaItem} then
            syncSmartAlbum("5 Stars")
        end if
end if
end tell

on syncSmartAlbum(dumbAlbumName)
tell application "Photos"
    set smartAlbumName to dumbAlbumName & " Smart"
    set smartAlbum to album smartAlbumName
    tell album dumbAlbumName to if exists then delete
    set newDumbAlbum to make new album named dumbAlbumName
    add (get media items of smartAlbum) to newDumbAlbum
end tell
end syncSmartAlbum

在此测试文件上运行时的结果为:

    tell current application
    offset of "." in "FEN.3700_CSD_s31m35h11_ta_52-21-5102/21/5102/otohp/aideM/EVIRD-G/semuloV/"
end tell
tell application "Finder"
    get name extension of alias "G-DRIVE:Media:photo:2015:12:2015-12-25_at_11h53m13s_DSC_0073.NEF"
    get name extension of alias "G-DRIVE:Media:photo:2015:12:2015-12-25_at_11h53m13s_DSC_0073.NEF"
    do shell script "/usr/local/bin/exiftool -config /Volumes/G-DRIVE/Scratch/customConfig -if 'defined $JustinApplePhotosID' -s -s -s -xmp:JustinApplePhotosID '/Volumes/G-DRIVE/Media/photo/2015/12/2015-12-25_at_11h53m13s_DSC_0073.NEF'"
end tell
tell current application
    do shell script "/usr/local/bin/exiftool -config /Volumes/G-DRIVE/Scratch/customConfig -if 'defined $JustinApplePhotosID' -s -s -s -xmp:JustinApplePhotosID '/Volumes/G-DRIVE/Media/photo/2015/12/2015-12-25_at_11h53m13s_DSC_0073.NEF'"
end tell
tell application "Photos"
    get every media item whose id = "tshx+Vk5TFC47a8Q5EeCiw"
    do shell script "/usr/local/bin/exiftool -s -s -s -keywords '/Volumes/G-DRIVE/Media/photo/2015/12/2015-12-25_at_11h53m13s_DSC_0073.NEF'"
end tell
tell current application
    do shell script "/usr/local/bin/exiftool -s -s -s -keywords '/Volumes/G-DRIVE/Media/photo/2015/12/2015-12-25_at_11h53m13s_DSC_0073.NEF'"
end tell
tell application "Photos"
    set keywords of media item id "tshx+Vk5TFC47a8Q5EeCiw" to {"4****"}
    get album "5 Stars"
    album id "b72G+JL2R5qyTJ%w0fAcqQ" contains {media item id "tshx+Vk5TFC47a8Q5EeCiw"}
    get album id "b72G+JL2R5qyTJ%w0fAcqQ"
end tell
tell current application
    current date
    (*2019:11:16:13:18:08: Error reading or setting keywords for /Volumes/G-DRIVE/Media/photo/2015/12/2015-12-25_at_11h53m13s_DSC_0073.NEF with error: Can’t make «class IPal» id "b72G+JL2R5qyTJ%w0fAcqQ" of application "Photos" into type list, record or text.*)
    open for access file "G-DRIVE:Scratch:Logs:UpdateKeywords.log" with write permission
    write "2019:11:16:13:18:08: Error reading or setting keywords for /Volumes/G-DRIVE/Media/photo/2015/12/2015-12-25_at_11h53m13s_DSC_0073.NEF with error: Can’t make «class IPal» id \"b72G+JL2R5qyTJ%w0fAcqQ\" of application \"Photos\" into type list, record or text.
" to 273 starting at eof
    close access 273
end tell
Result:
true

出现问题的错误似乎是:无法将应用程序“照片”的«class IPal»id“ b72G + JL2R5qyTJ%w0fAcqQ”设置为类型列表,记录或文本

我在这里做错了什么?

applescript photo
1个回答
0
投票

想通了。显然不能问专辑是否“包含”某项。解决方法:

        set FiveStarPhotos to (id of media items of album "5 Stars")

        if keywordArray contains "5*****" and FiveStarPhotos does not contain {mediaItem} then
            add {mediaItem} to album "5 Stars"
        else if keywordArray does not contain "5*****" and FiveStarPhotos contains {mediaItem} then
            syncSmartAlbum("5 Stars")
        end if
© www.soinside.com 2019 - 2024. All rights reserved.