如何为苹果脚本传递参数
How to pass argument for the apple script
我有以下脚本:)
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
这有助于我转换 doc 和 docx 文件 -> pdf,但它的交互性太强了。
我想通过终端 运行 这个脚本,我想传递文件路径或目录作为参数
例如:
$ script /Users/test/dest_dir/ /Users/test/out_dir/
会将所有 pdf 文件生成为 out_dir。
我也看到了这个库,但它只转换 docx 文件:
https://pypi.org/project/docx2pdf/
这里有没有人可以帮我重写这个脚本..我根本不懂这种语言。或者也许有人会指出完成的工具。我需要在 mac os 操作系统上执行此操作。
见http://hints.macworld.com/article.php?story=20050523140439734
argv 是字符串格式的参数数组
on run argv
return item 1 of argv
我有以下脚本:)
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
这有助于我转换 doc 和 docx 文件 -> pdf,但它的交互性太强了。
我想通过终端 运行 这个脚本,我想传递文件路径或目录作为参数 例如:
$ script /Users/test/dest_dir/ /Users/test/out_dir/
会将所有 pdf 文件生成为 out_dir。
我也看到了这个库,但它只转换 docx 文件: https://pypi.org/project/docx2pdf/
这里有没有人可以帮我重写这个脚本..我根本不懂这种语言。或者也许有人会指出完成的工具。我需要在 mac os 操作系统上执行此操作。
见http://hints.macworld.com/article.php?story=20050523140439734
argv 是字符串格式的参数数组
on run argv
return item 1 of argv