applescript - 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
解决方案
两个问题:
- 你必须设置
thisPlaceholderImageItem
为image 1
而不是item 1
- 您必须设置
file name
tolatestFile
而不仅仅是 toalias
。这就是错误告诉你的。
如果该文件夹是桌面的子文件夹,则语法要短得多
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
推荐阅读
- android - Android Studio 折叠代码块在返回项目后展开
- javascript - 为什么firebase cloud-function javascript promise运行的次数超过循环调用的次数?
- reactjs - 如何在 mui 数据表的同一列中显示名字和姓氏?
- java - 向 aws lambda 发出请求时,Gitlab runner 一直运行直到超时
- python - 如何检测一个单词然后使用 discord.py 在 dm 中发送消息?
- android-studio - Android Studio 无法解析 dart 文件中的嵌套导入
- python - 使用 pandas 在 Python 中将对象数据类型转换为日期时间数据类型
- python - 中心和权威分数:networkx vs igraph
- html - 如何创建快捷方式以在 VS Code 中围绕选定文本添加标签
- c++ - Valgrind:可以接受越来越多的可能丢失的字节吗?