Applescript - 在 PowerPoint 演示文稿中创建新幻灯片失败,因为加载速度不够快
Applescript - Creating a new slide in a PowerPoint presentation fails because it doesn't load fast enough
这是我的 AppleScript 示例:
tell application "Microsoft PowerPoint"
activate
if active presentation exists then
else
make new presentation
end if
set newSlide to make new slide at the end of active presentation
make new picture at newSlide with properties {file name:"blahblahHFSfilepath", height:100, width:100, lock aspect ratio:true}
end tell
这有效——但前提是 PowerPoint 已经打开。如果未打开,此脚本将打开 PowerPoint,并创建一个新的演示文稿。然后它会尝试创建一张新幻灯片,但由于当 PowerPoint 首次加载演示文稿时尚未创建,因此会发生错误。我断定这是问题所在,因为如果我在 make new presentation
行后面放一个 delay 1
,它就会起作用。
有没有一种方法可以确定演示文稿是否已创建完毕,然后制作新幻灯片?或者在这种情况下延迟是最好的途径吗?我担心的是,较旧的机器可能需要更长的时间来创建演示文稿。
对我来说,我想我只需要有类似 "wait until new presentation is created, and THEN create new slide" 的东西,但我不知道该怎么做。
那里有任何 AppleScripter 知道简单的解决方案吗?
谢谢!
将make new presentation
的结果放入一个变量,用这个变量代替active presentation
。
试试这个:
tell application "Microsoft PowerPoint"
activate
if active presentation exists then
set aPres to active presentation
else
set aPres to make new presentation
end if
set newSlide to make new slide at the end of aPres
make new picture at newSlide with properties {file name:"blahblahHFSfilepath", height:100, width:100, lock aspect ratio:true}
end tell
这是我的 AppleScript 示例:
tell application "Microsoft PowerPoint"
activate
if active presentation exists then
else
make new presentation
end if
set newSlide to make new slide at the end of active presentation
make new picture at newSlide with properties {file name:"blahblahHFSfilepath", height:100, width:100, lock aspect ratio:true}
end tell
这有效——但前提是 PowerPoint 已经打开。如果未打开,此脚本将打开 PowerPoint,并创建一个新的演示文稿。然后它会尝试创建一张新幻灯片,但由于当 PowerPoint 首次加载演示文稿时尚未创建,因此会发生错误。我断定这是问题所在,因为如果我在 make new presentation
行后面放一个 delay 1
,它就会起作用。
有没有一种方法可以确定演示文稿是否已创建完毕,然后制作新幻灯片?或者在这种情况下延迟是最好的途径吗?我担心的是,较旧的机器可能需要更长的时间来创建演示文稿。
对我来说,我想我只需要有类似 "wait until new presentation is created, and THEN create new slide" 的东西,但我不知道该怎么做。
那里有任何 AppleScripter 知道简单的解决方案吗?
谢谢!
将make new presentation
的结果放入一个变量,用这个变量代替active presentation
。
试试这个:
tell application "Microsoft PowerPoint"
activate
if active presentation exists then
set aPres to active presentation
else
set aPres to make new presentation
end if
set newSlide to make new slide at the end of aPres
make new picture at newSlide with properties {file name:"blahblahHFSfilepath", height:100, width:100, lock aspect ratio:true}
end tell