首页 > 解决方案 > How do get last downloaded image to insert into object placeholder of current keynote slide?

问题描述

Images are key to my work.

I am trying to find a quick way to automate image insertion to keynote. The script I am drafting is to get the last created/downloaded image, and insert it into the current slide on Keynote as a replacement of the master's object placeholder.

Error from applescript:

"Keynote got an error: Can’t set file name of slide 2 of document id \"B1054797-9A07-4642-AE79-166D1DE72674\" to alias." number -10006 from file name of slide 2 of document id "B1054797-9A07-4642-AE79-166D1DE72674" to alias

set myFolder to "/Users/Mingyu/Desktop/UpperEchelon"

tell application "Finder" to set latestFile to item 1 of (sort files of (POSIX file myFolder as alias) by creation date) as alias
tell application "Keynote"
    activate
    tell the front document
        tell the current slide
            set thisPlaceholderImageItem to item 1
            set file name of thisPlaceholderImageItem to ¬
                alias
        end tell
    end tell
end tell

I expect the script will insert last download image in the folder "UpperEchelon" to a current open slide in Keynote

标签: applescript

解决方案


两个问题:

  1. 你必须设置thisPlaceholderImageItemimage 1而不是item 1
  2. 您必须设置file nametolatestFile而不仅仅是 to alias。这就是错误告诉你的。

如果该文件夹是桌面的子文件夹,则语法要短得多

set myFolder to "UpperEchelon"

tell application "Finder" to set latestFile to item 1 of (sort files of folder myFolder by creation date) as alias
tell application "Keynote"
    activate
    tell the front document
        tell the current slide
            set thisPlaceholderImageItem to image 1
            set file name of thisPlaceholderImageItem to latestFile
        end tell
    end tell
end tell

推荐阅读