首先,我是一个初学者AppleScript开发人员。我已经搜索了这个问题很长一段时间,但没有找到结果。我有一个AppleScript转换为pdf格式的ppt文件。但是脚本在匹配一个坏的ppt文件后会挂起。
脚本/注释记号将弹出一个对话框,显示"xxx.ppt当前无法打开“”文件格式无效“。
有没有办法防止keynote弹出这样的对话框?
下面是示例代码,file是一个图像文件,但我将扩展名改为pptx以模拟一个非法文件:
set thefile to POSIX file "/Users/dazhangluo/Downloads/brain-storming.pptx"
tell application "Keynote"
activate
try
set thedoc to open thefile
--display dialog class of thedoc
on error errMessage
--display dialog errMessage
log errorMessage
end try
end tell
发布于 2021-10-09 16:48:11
有一个名为exiftool
的命令行工具,它可以检查文件并获取它们的元数据,包括“文件类型”标签(使用-filetype
)。有很多种方法可以安装†。与'mdls‘不同,它不容易被文件扩展名愚弄。如果您在pptx文件上运行它,它将在其结果中包含以下内容:
File Type : PPTX
然后,您可以抓取要测试的最后一个单词。此脚本将遍历指定文件夹中的文件,使用exiftool提取其文件类型,然后将任何匹配文件的别名复制到新列表中。然后在注释记号中打开每个文件。我的keynote版本(v8)不允许我使用powerpoint文档编写任何脚本,所以在这一点上您只能靠自己。
set srcFol to (path to desktop as text) & "presentations" as alias
-- or if you prefer…
-- set srcFol to choose folder
tell application "Finder"
set fList to files of srcFol as alias list
set cleanList to {}
repeat with f in fList
set ppFile to POSIX path of f
set qfFile to quoted form of ppFile
tell me to set exifData to do shell script "/usr/local/bin/exiftool -filetype " & qfFile
if last word of exifData is "PPTX" then
set end of cleanList to contents of f
--> alias "Mac:Users:username:Desktop:presentations:powerpoint1.pptx"
end if
end repeat
end tell
tell application "Keynote"
activate
repeat with pptxFile in cleanList
open pptxFile
-- do whatever
end repeat
end tell
注意:根据exiftool安装位置的不同,您可能需要更改which exiftool
†的路径。
https://stackoverflow.com/questions/69505409
复制相似问题