Inès Zarka
Inès Zarka

Reputation: 81

Show specific Quick Action for specific file extension

I am newbie with Applescript and Automator. I am trying to build a Quick Actions which will be able to propose different functions according to the type of file for example. If the file is test.sh quick action will be a and b If the file is document.pdf action will be c and d

I succeed in creating my actions but not to make them specific to file type. I don't know where to start as I don't see any possibility to make input conditional like if input = .sh do a and b.

Any help on how to proceed will be really appreciated.

Thank you, enter image description here

Upvotes: 0

Views: 1487

Answers (2)

Ted Wrigley
Ted Wrigley

Reputation: 3194

Quick Actions are meant to be type-specific, so in general the best practice is to write one Quick Action for each file type. These quick actions will only appear in the Finder when files of that type are selected.

In many cases you can specify the file type when you create or edit the Quick Action in Automator. For instance, to create a Quick Action that appears only when PDF files are selected, set the pulldown menus at the top of the workflow to say "Workflow receives current PDF files in Finder":

Automator workflow header

then complete and save the Quick Action.

If you want more fine-tuned control over what types of files the Quick Action 'sees', you can edit its info.plist file and change its file types. After you've saved the Quick Action, navigate to ~/Library/Services in the Finder (that's the Services folder in the Library folder of your Home folder). Find the package with the name of the Quick Action (e.g., "Open in Preview"), control-click on it to get the contextual menu, choose Show Package Contents, and then open the Contents folder. You'll see the following:

enter image description here

Open that info.plist file in a plain-text text editor — I prefer BBEdit, but TextEdit will work fine if you make sure 'rich text' is turned off — and look for the NSSendFileTypes key. It will look something like the following:

    <key>NSSendFileTypes</key>
    <array>
        <string>com.adobe.pdf</string>
    </array>

com.adobe.pdf is a Uniform Type Identifier (UTI), and you can add or substitute in any system-recognized UTI. Here is the list of system-declared UTIs, but applications can declare their own UTIs and register them with the system, so this list is not necessarily exhaustive. For instance, if you want your Quick Action to send both PDFs and image files to Preview, you would search on the system-declared UTIs page and find that the base UTI for images is public.image, and then edit the info.plist to read:

    <key>NSSendFileTypes</key>
    <array>
        <string>com.adobe.pdf</string>
        <string>public.image</string>
    </array>

Save this, and the Quick Action will now appear whenever you selected PDFs or images. Note that if you manually edit the info.plist file it might get overwritten if you edit and save the Quick Action in Automator.

Only the first two relevant Quick Actions will appear in the Finder window; any extras will be collapsed under the more button. To change the ordering so that the Quick Actions you use most are up first, open System Preferences, click the Extensions item, open the Finder section, and drag the items in the right-hand list into the order you prefer.

Upvotes: 3

user3439894
user3439894

Reputation: 7555

After looking at the image of your QuickAction, it is not at all useful for anything other then a selected PDF document in Finder.

The first action should be a Set Value of Variable action so its contents can be retrieved multiple times using Get Value of Variable with however many Filter Finder Items actions needed to process the different file types, followed by the appropriate actions for each file type.

You would also use Ignore this action's input checkbox under Options for this action to detach it from the previous set of actions.

The image below shows a rough outline example of what I'm referring to:

enter image description here

Upvotes: 2

Related Questions