How to systematically change a default app for files in a given folder

applescriptapplicationsfinder

I would like all of the (say) pdf files that land in my Download folder to open with (say) Acrobat instead of my default Preview (but I want to retain Preview as a default for all other pdf files).

I know how to do that by hand through the finder, but I would like that to be done automatically whenever a file is added to the Download folder.

I take pdf as an example but I would like this to be feasible with any file extension.

As a bonus, the default would revert to Preview when the file is moved from Download to another folder.

Thanks !

Best Answer

Save this following AppleScript code to… /Users/YOUR SHORT NAME/Library/Workflows/Applications/Folder Actions ..folder as a script file. You can name it something like “Change Default Application.scpt”

I don't have Acrobat reader on my system so I used TextEdit.app as one of my variables instead. You can change that value in line 2 of the code, to suit your needs. Line 3 of the code is what tells the script which application to use as the default app for the PDF files located within the folder that the folder action is attached to.

property Default_App_To_Open_With1 : alias "Macintosh HD:Applications:Preview.app:"
property Default_App_To_Open_With2 : alias "Macintosh HD:Applications:TextEdit.app:"

property Default_App : Default_App_To_Open_With2

property name_Extension : "pdf"

on adding folder items to this_folder after receiving dropped_items
    repeat with this_File in dropped_items
        tell application "System Events"
            if name extension of this_File is name_Extension then
                set default application of this_File to Default_App
            end if
        end tell
    end repeat
end adding folder items to

After this code is tweaked to your liking, and has been saved to the previous mentioned folder, it will then be available to use within the Folder Actions Setup.app to to attach to any folder of your choice

enter image description here