0

我需要访问关键字的名称属性以在 iPhoto 中选择照片。如何访问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
4

1 回答 1

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)变量的方式,如果是这样,请将该代码也包含在您的问题中。

于 2014-09-02T23:05:31.157 回答