Return 来自 Applescript 中的多个列表选择的结果

Return results from multiple list choice in Applescript

此脚本用于 Capture One,我在其中将人名分配给 EXIF 数据。

我正在尝试 return 列表的结果,该列表可能是用户做出的一个或多个选择。我可以使用列表中的第 1 项来使用它,但我不知道如何处理从列表中的任何位置选择 2 个或更多名称的人?

感谢您提供的任何帮助。

tell application "Capture One 11"
set peopleChoices to {"Abbie", "Charlie", "De-Arne", "Dean", "Jason", "Marlene", "Peta ", "Phoenix", "Rod", "Vanessa", "Yvonne"}
set peopleList to choose from list peopleChoices with prompt "Select your keyword/s:" with multiple selections allowed
if the result is not false then
set exif_keywords to item 1 of the result
end if
set selectedVariants to get selected variants
repeat with i from 1 to number of items in selectedVariants
    set this_item to item i of selectedVariants
    set theID to id of (parent image of this_item)
    do shell script "/usr/local/bin/exiftool -Subject='" & exif_keywords & "' -m -overwrite_original_in_place " & quoted form of theID
    reload metadata this_item
end repeat
display dialog "EXIF data has been updated"
end tell

您将列表限制为该行中的一项

set exif_keywords to item 1 of the result

改成

set exif_keywords to result

我不知道关键字应该如何在 exiftool 行中传递,您可以用 text item delimiters 将列表展平,本示例加入列表以逗号分隔。如果参数必须 space 分隔,请将 "," 替换为 space

set {ASTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ","}
set exif_keywords to exif_keywords as text
set AppleScript's text item delimiters to ASTID

我在下面包含了整个工作脚本,以防其他人正在寻找类似的东西。 “-sep”是 exiftool 的一部分,它根据你在它后面放的内容来分割字符串。我不得不为 shell 脚本行转义它,但它通常没有反斜杠。

tell application "Capture One 11"
    set peopleChoices to {"Abbie", "Charlie", "De-Arne", "Dean", "Jason", "Marlene", "Peta", "Phoenix", "Rod", "Vanessa", "Yvonne"}
    set peopleList to choose from list peopleChoices with prompt "Select your keyword:" with multiple selections allowed
    if the result is not false then
        set exif_keywords to result
        set {TID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ","}
        set exif_keywords to exif_keywords as text
        set AppleScript's text item delimiters to TID
    end if
    set selectedVariants to get selected variants
    repeat with i from 1 to number of items in selectedVariants
        set this_item to item i of selectedVariants
        set theID to id of (parent image of this_item)
        do shell script "/usr/local/bin/exiftool -sep \",\" -Keywords='" & exif_keywords & "' -m -overwrite_original_in_place " & quoted form of theID
        reload metadata this_item
    end repeat
    display dialog "EXIF data has been updated"
end tell