如何为苹果脚本传递参数



我有以下脚本:(

property word_docs : {"org.openxmlformats.wordprocessingml.document", "com.microsoft.word.doc"}
property default_path : (path to desktop) as alias
property Delim : {".docx", ".doc"}
property PDF : ".pdf"
set outPDF to {}
set selected_files to (choose file of type word_docs default location default_path with multiple selections allowed without invisibles and showing package contents)
set {TID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, Delim}
repeat with afile in selected_files
copy item 1 of text items of (afile as text) & PDF to the end of outPDF
end repeat
set AppleScript's text item delimiters to TID

tell application id "com.microsoft.Word"
activate
repeat with i from 1 to count of selected_files
open (item i of selected_files)
set theOutputPath to (item 1 of outPDF)
-- close access (open for access exportDocument)
tell active document
save as it file name theOutputPath file format format PDF
close saving no
end tell
end repeat
end tell
return

这有助于我转换文档&docx文件->pdf,但它太互动了。

我有通过终端运行这个脚本的想法,我想传递文件路径或目录作为参数例如:

$ script /Users/test/dest_dir/ /Users/test/out_dir/

将所有pdf文件生成到out_dir中。

我也看到了这个库,但它只转换docx文件:https://pypi.org/project/docx2pdf/

这里有人能帮我重写这个剧本吗。。我一点也不懂这种语言。或者有人会指着完成的工具。我需要在macos操作系统上执行此操作。

请参阅http://hints.macworld.com/article.php?story=20050523140439734

argv是字符串格式的参数数组

on run argv
return item 1 of argv

最新更新