0

Apple Script 应该如何自动打开下载到 Downloads 文件夹的名为 testfile 的文件并使用程序 testprogram 运行?

我觉得它应该是一个非常简单的模板,我很难找到很多东西来完成它。

4

2 回答 2

2

此示例使用 Microsoft Word 打开 testFile.rtf。使用您的信息更新代码并将文件夹操作附加到您的目标文件夹。

on adding folder items to theFolder after receiving theFiles

    set appPath to quoted form of (POSIX path of (path to applications folder) & "Microsoft Office 2011/Microsoft Word.app")

    repeat with aFile in theFiles
        tell application "Finder" to aFile's name = "testfile.rtf"
        if the result then
            set filePath to quoted form of aFile's POSIX path
            do shell script "open -a " & appPath & space & filePath
        end if
    end repeat
end adding folder items to

如果您要手动打开文件,请尝试以下操作:

set appPath to quoted form of (POSIX path of (path to applications folder) & "Microsoft Office 2011/Microsoft Word.app")
set filePath to quoted form of (POSIX path of (path to documents folder) & "testFile.rtf")
try
    do shell script "open -a " & appPath & space & filePath
end try
于 2013-09-11T13:59:26.253 回答
1

您可以使用 Automator 创建这样的文件夹操作:

Finder 的open命令还有一个using用于指定应用程序的说明符:

tell application "Finder"
    open POSIX file "/usr/share/doc/bash/bash.html" using (path to application "Safari")
end tell
于 2013-09-12T17:39:58.480 回答