Adding a script to MacOS finder contextual menu

后端 未结 3 1097
礼貌的吻别
礼貌的吻别 2020-12-24 05:08

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

相关标签:
3条回答
  • 2020-12-24 05:43

    The steps have changed for Snow Leopard/10.6+ since @khachik's correct answer. To make sure its clear, here are the steps:

    • Open Automator
    • Create a new Service
    • Set the top two drop downs across the top to "Service receives selected files or folders in Finder.app"
    • Set Pass input to as arguments
    • Write your script (see below for that).
    • Save and choose the service name

    Your Automator window should look like the this: :screenshot

    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 $@
    
    0 讨论(0)
  • 2020-12-24 05:44

    Yeah, I know this is third party software - but for the sake of a fuller overview - http://www.abracode.com/free/cmworkshop/on_my_command.html. Another tool that would make your script writing easier is http://wafflesoftware.net/thisservice/ adding items to the service menu.

    0 讨论(0)
  • 2020-12-24 05:59

    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>.

    0 讨论(0)
提交回复
热议问题