I want to add an option to the finder context menu that calls hg add %1
with %1 being the full path of the selected file in finder.
Of course there are more useful cases I can think of, to add to the context menu.
Is there a simple way to do that which doesn't involve installing any 3rd party software or coding in a compiled language and building binary plugins?
Like creating a script with the script editor and dropping it in /Library/Contextual Menu Items/
?
Customize Contextual Menus with AutomatorStart Automator from your Applications folder or Launchpad. Choose Service for your document. At the right-hand panel, select "files or folders" in "Service receives selected". Then, at the left-hand panel, select Files & Folders > Rename Finder Items.
In the Script Editor app on your Mac, save your script as a file in the Finder, then copy the file into the Script Editor Scripts folder (located in the Script folder in the Library folder on your startup disk).
The steps have changed for Snow Leopard/10.6+ since @khachik's correct answer. To make sure its clear, here are the steps:
Service
files or folders
in Finder.app
"as arguments
Your Automator window should look like the this: :
You can now select multiple files in Finder and then execute your service from the Services sub-menu.
For your script, I think you want the following. This changes to each argument's directory then adds it. I'm using a for loop because Finder allows you to select multiple files in different folders (which could be in different repositories).
for f in "$@"
do
cd $(dirname $f); hg add $f
done
If you assumed they are all in the same repository you could do this:
cd $(dirname $1); hg add $@
Open Automator, create a custom workflow. From Library
choose Utilites
, then drag and drop Run shell script
to the workflow. Set Pass input
to As arguments
. Write in your script: hg add $1
. Then File menu->Save as a Plugin
, specify the name, choose plugin for Finder
, Save
. Right click on the file, choose More->Autamator-><PLUGIN_NAME>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With