在iPhoto中访问照片的“关键字”元素 - Applescript

时间:2014-09-02 20:17:31

标签: applescript iphoto

我需要访问iPhoto中选定照片的关键字的name属性。如何访问这些照片的keyword元素?我可以访问照片的属性,但不能访问keyword元素。

我是Applescript的新手,所以如果这是非常无趣的话我会道歉。感谢您提供的任何帮助。

编辑:这是我尝试过的。

set keywordsRef to a reference to keyword of p     --p is a photo
set keyName to name of keywordsRef

我收到错误-1700。不确定这是否有帮助。

编辑2:

tell application "iPhoto"
    activate
    try
        set myPhotos to selection

        if myPhotos is false or (the count of myPhotos) is 0 then
            error "Please select an image"
        end if

        repeat with p in myPhotos
            set keyname to the name of keyword 1 of p    --This works.
            set xmldata to xmldata & my addNewPhoto(p)   --Try to get keywords here.
        end repeat
    on error
        --display dialog "Error"
    end try
end tell

on addNewPhoto(p)
    set photodata to "<dict>" & return & my addPhotoName(name of p)  --This works.

    --set keyname to the name of keyword 1 of p            --This gets a syntax error at the "1" after keyword. It expects the end of line.

    set keycount to the count of keywords of p
    repeat with i from 1 to keycount
        --log (the name of keyword i of p as string)        --Syntax error also at "i" after keyword.
    end repeat

    set photodata to photodata & my addPhotoKeywords()
    set photodata to photodata & "</dict>" & return
end addNewPhoto

1 个答案:

答案 0 :(得分:1)

鉴于你的照片有关键字,这对我有用。

tell application "iPhoto"

    set p to photo id 4.294981127E+9

    set keyname to the name of keyword 1 of p

end tell

通过它们循环:

tell application "iPhoto"

    set p to photo id 4.294981127E+9

    set keycount to the count of keywords of p

    repeat with i from 1 to keycount
        log (the name of keyword i of p as string)
    end repeat

end tell

如果这些不起作用,可能就像初始化照片(p)变量一样,如果是这样,也会在你的问题中包含该代码。