BAR
BAR

Reputation: 17121

Applescript Auto Open Downloaded File

How should an Apple Script look like to automatically open a file named testfile downloaded to the Downloads folder and run with a program testprogram?

I feel it should be a pretty simple template, and I am having trouble finding much to accomplish it.

Upvotes: 0

Views: 851

Answers (2)

Lri
Lri

Reputation: 27613

You could create a folder action like this with Automator:

Finder's open command also has a using specifier for specifying the application:

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

Upvotes: 1

adayzdone
adayzdone

Reputation: 11238

This example uses Microsoft Word to open testFile.rtf. Update the code with your info and attach the folder action to your target folder.

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

If you manually want to open the file, try this:

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

Upvotes: 2

Related Questions