一种可能的解决方法是循环检查打开的演示文稿,并将其与之前已经打开的演示文稿进行比较。
首先,当此脚本开始运行时,它会检查 PowerPoint 是否正在运行(-> 如果没有则退出)。如果 PP 运行,则脚本记录打开的演示文稿的数量。
然后脚本通过一个循环:在这个例子中,它重复了 100 次(只是为了我的测试,但它应该永远重复!)。对于每次迭代,它都会查找 PP 演示文稿列表并与之前的列表进行比较:如果演示文稿不在之前的列表中,那么它是新的,直接打开!
当您退出 PowerPoint 并显示警报(块尝试)时,该脚本也会停止。
tell application "System Events" to set PP_Running to exists (processes where name is "Microsoft PowerPoint")
if not PP_Running then return -- Power point is not launched !
tell application "Microsoft PowerPoint" to set Old_list to name of every presentation -- get initial list of open presentations
repeat with I from 1 to 100 -- for test, but it should be repeat with no limit
try
tell application "Microsoft PowerPoint" to set New_list to name of every presentation
on error
display alert "PowerPoint no longer launched"
return -- quit the loop
end try
repeat with aDoc in New_list
if not (Old_list contains aDoc) then -- new document has been opened !!
set Old_list to New_list
log "Open new document = " & aDoc -- do what ever you need to do !!
end if
end repeat
delay 0.5
set I to I + 1
end repeat
在 El Capitain / PP 2011 上测试:但我认为“每个演示文稿的名称”从 PP 2011 到 PP 2016 没有任何变化。