0

I have a folder with a single filetype including subdirectories that I'm trying to open with a default application. For example, I have about 3 text editors and I need to open txt files in a folder1 with text-editor-1 and folder2 with text-editor-2 by default.

Any suggestions on how I could create a default app for these specific folder's filetypes? Only 1 filetype could be useful, and hopefully via Scripts or Automation.

I'm new to Mac, so haven't tried any alternative app/utility that supports this.

Thanks.

  • do the files have the same extensions? You can tell mac which application to use on certain extensions. – jmh Oct 17 '17 at 2:53
  • Ya, they have same extensions although that would change defaults for the file type and I’m trying to change for the folder specific files only. Default app for a file type in that particular folder only. – mk117 Oct 17 '17 at 10:15
2

In Finder, in any folder, you can select multiple files then control + click, you will see the menu item “Open With”. Continue holding the control key then press the option key and you will see the menu item “Open With” changes to “Always Open With”. Click that “Always Open With” menu item, choose the default application you want to use to open those files. This will change the default Application for those files only. Just follow this process with all the files in the different folders. Again the process will not take long because you can select multiple files at once and change their default applications.


If you save this following script to your /Users/your username/Library/Workflows/Applications/Folder Actions folder, it will be available to select in the folder actions set up dialogue. Then every time you add a text file to the designated folder, it will set the default application to which ever text editor you assigned in the script.

Basically you create three different versions of this folder action script and asign a different text editor variable in each script to use on the different folders.


I rearranged the script a little bit to make it a bit more universal. Now it's easier to tweak the code to work with different file extensions and different applications, just by changing the property values while leaving the body of the script completely intact.

This script will target ONLY THE .txt's, no matter what type of file gets added to the folder

property Default_App_To_Open_With1 : alias "Macintosh HD:Applications:TextWrangler.app:"
property Default_App_To_Open_With2 : alias "Macintosh HD:Applications:TextEdit.app:"
property Default_App_To_Open_With3 : alias "Macintosh HD:Applications:BBEdit.app:"

property Default_App : Default_App_To_Open_With3

property name_Extension : "txt"

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
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.