Context menu, Send folderitem path to App

I’m trying to figure out how do I create a context menu entry for my app, that will show in Mac Finder with any contextual click on any file type and folder. it should send the folderitem as a path argument to my App.
It’s very easy (for me) on Windows, as I add a registry key to both All File Types and Directory in the Windows installer builder application. with the value:
"%ProgramFiles%\Manufacturer\App Name\App Name.exe" "%1"
I can even add another “fixed” argument like so:
"%ProgramFiles%\Manufacturer\App Name\App Name.exe" "%1" "C:\temp"

Here’s how it looks, and work, on Windows:


Obviously, it should work for any user installing my application, so I assume creating an Automator service is not a good solution, or maybe it is? (not that I know how to do it anyway).

Thanks for any guidance you may have to offer :pray:

AFAIK the additional entries to the context menu are called services. Unfortunately, there are quite a few things called service. Which makes goggling suck lemons. I was able to find some legacy docs at Introduction .

Not sure if this is related: Apple Developer Documentation

Thanks @Beatrix_Willius , Yeah, I also found that this is a tough thing to narrow down. Everything I try to search on the subject brings me tons of semi related results but none are exactly what I’m looking for.

AFAIK, you can add a service (as Beatrix said) but it will always show up in the Services submenu.

If you want to add a submenu somewhere else, you would need to make a Finder extension but that’s really not easy

Thanks @Stéphane_Mons , I thought someone will say it’s easy, just write a simple AppleScript with…
But I guess it’s more complicated;)
Still optimistic that someone will offer an easy solution :grinning:

Does it have to forcibly be in the contextual menu? A service can also be shown in the, so well named, “Services” menu (see the app’s menu of any running app).
This has the benefit of working with any apps, not just the Finder (for instance, think about the users of Path Finder who often don’t use the Finder at all).

I didn’t know there are mac users who don’t use the Finder at all. I’m not a mac savvy, not even consider myself a mac user even though I often use it and code on it a lot.
If you all say ‘Services’ is the way to go, I will not argue because you are all more experienced than me when it comes to mac. My only question is how. Can you share any docs link that shows step by step how to set it up?

The beauty of PC that everything I look for is so easy to find. I just need to pick the most convenient method for any given scenario. With Mac, I always find myself spending more time finding ‘A’ working solution, while for PC, I spend more time finding ‘The’ solution.
Funny. Maybe it’s only me.

You want to be able to right click a file in Finder and have it open in your application right?

Make sure you set-up the file types in your project as the Mac will use the file type specifications to determine which apps can open what files (and priority).

This may explain how to do it: automator - Run Command Line Script from Finder's contextual menu - Ask Different

Hi @Sam_Rowlands, I have my app configured so that it accepts all file types and folders as a path argument. the user can filter the file types within the app, and even build file types filtering presets for himself, that way any user can handle different things according to one’s needs.

@Matthew_Dinmore1 , This looks like the right path to an elegant solution.
So if I want to pass the arguments to my app, is it right to adjust the script like so:

for f in "$@"
do
open -a "My App" "$f"
done

Or maybe I don’t even need the loop:

open -a "My App" "$@"

I hope I’m in the right direction (my aim is not to statically refer to my app’s location) and pass all items (if there is more than one folderitem coming in)

Thank you for the help, much appreciated.

Assuming your app is set up to receive files is in the normal way (i.e. app OpenDocument handler), it’s probably even easier:

  1. Open Automator; start a Service/Quick Action project
  2. Select “Workflow received current files or folders in Finder
  3. Drag “Open Finder Items” into the flow
  4. Set “Open With” to your app
  5. Save as… whatever name you want to appear in the context menu

You should now be able to go to the finder, right-click a file, and select your action from the Services menu. You can find the service in your Library Services (~/Library/Services/) folder if you want to redistribute it.

1 Like

Thanks @Matthew_Dinmore1 !
In the meantime, I already built it with a simple Shell Script like so:

open -a "Dir Organizer.app" "$@"

It works great so far, but I’ll try your method as well to get to know all options;)

Now I wonder, how do I include this service with my app?
Should I put it in my app ‘Resources’, check if it exists in (~/Library/Services/) on every launch, and copy it there if it’s not?

Should I put it in my app ‘Resources’, check if it exists in (~/Library/Services/) on every launch, and copy it there if it’s not?

Probably, or if you have an installer, use that.

1 Like
Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.