Applescript自动打开下载的文件

时间:2013-09-10 17:21:59

标签: applescript

Apple Script如何自动打开一个名为testfile的文件,下载到Downloads文件夹并运行程序测试程序?

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

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:1)

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

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

tell application "Finder"
    open POSIX file "/usr/share/doc/bash/bash.html" using (path to application "Safari")
end tell