Launch different apps based on file name (other than the extension)

applescriptbashfinderlaunch-servicesscript

I'd like to have different apps handle .jpg files based on a naming convention I'll use for the .jpg files. Specifically most will go to Xee, but ones containing thumb should instead cause VLC to be called with the same path and file name, but with .mp4 (or .mkv, etc.) extension.

Is there an existing script / app that does this? I'm guessing the way to do it would be to create a shim app (sort of like choosy) that handles the main file type based on extension, and then hands off to the apps you configure based on a ruleset.

Best Answer

Just create an Applescript Droplet to read the name and extension of dropped files and triage them with if statements. This script should get you started. Save it as an application, and then you can put it in your dock or some place convenient to drop files on it.

on open these_items
    repeat with i from 1 to the count of these_items
        set this_item to item i of these_items
        set the item_info to info for this_item without size
        set theName to name of item_info
        try
            set theExtension to the name extension of item_info
        on error
            set theExtension to ""
        end try

        if theName contains "thumb" then
            tell application "VLC"
                activate
                open this_item
            end tell
        else if theExtension contains "jpeg" then
            tell application "Preview"
                activate
                open this_item
            end tell
        else
            -- open with system default app
            tell application "Finder" to open this_item
        end if
    end repeat
end open