如何在当前 Keynote 文档中 select 当前幻灯片上的一张特定图像?

How do I select one specific image on the current slide in the current Keynote document?

使用 AppleScript,我想在 Keynote 文档的每张幻灯片上更改特定图像的 xy 位置。一旦 Keynote 是 运行 并激活,下面的代码就可以工作...

tell the front document
   set the current slide to slide 1
   tell the current slide
      set thisImage to image 1
      set position of thisImage to {10,10}
   end tell -- current slide
end tell -- front document

...但它太脆弱了。如果我的图像不是第一个 ("image 1"),那么我将更改错误对象的位置。我在脚本词典或在线示例中找不到任何关于表达特定图像的对象说明符的内容。我尝试了多种变体,例如...

set thisImage to image with file name "my-file.png"

...无济于事。任何和所有的建议表示赞赏。谢谢!

这在 Keynote 8.2 中有效,但老实说,我不确定为什么。

set thisImage to image {name:"my-file.png"}

但是,如果你想问 thisImage 它的 name 是什么,你必须问它的 文件名,例如…

file name of thisImage

每次我使用任何演示软件时,我都不太喜欢它们。

你有一些冗余(大约 'current slide')所以这是我的看法:

tell slide 1 of the front document
    set thisImage to image {name:"my-file.png"}
    set position of thisImage to {10, 10}
end tell

最后,由于您的 objective 是循环浏览幻灯片中的每张幻灯片,您可以试试这个:

tell front document
    repeat with i from 1 to count of slides

        tell slide i to set position of image {name:"my-file.png"} to {10, 10}

    end repeat
end tell

经进一步审查,较早的答案无效,或不再有效。显然是名称说明符...

set thisImage to image {name:"my-file.png"}

... 实际上并没有以那种方式指定名称。这是我丑陋的解决方法:

tell the current slide
    set imageCount to the count of images
    repeat with i from 1 to imageCount
        set thisImage to image i
        if file name of thisImage = "myTargetFile.png" then
            set position of thisImage to {10, 10}
            exit repeat -- Ugly programming, look away.
        end if
    end repeat
end tell