Is it possible to use a shell script in the sendto folder?

Solution 1:

This will enable Drag & Drop to any script. You can place one of them in SendTo folder and use it afterwards.

Registry Export:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\ShellFile]

[HKEY_CLASSES_ROOT\ShellFile\Shell]

[HKEY_CLASSES_ROOT\ShellFile\Shell\Open]

[HKEY_CLASSES_ROOT\ShellFile\Shell\Open\Command]
@=hex(2):43,00,3a,00,5c,00,70,00,61,00,74,00,68,00,5f,00,65,00,78,00,74,00,5c,\
  00,62,00,61,00,73,00,68,00,2e,00,65,00,78,00,65,00,20,00,2d,00,63,00,20,00,\
  22,00,73,00,6f,00,75,00,72,00,63,00,65,00,20,00,24,00,30,00,3b,00,72,00,65,\
  00,61,00,64,00,22,00,20,00,25,00,31,00,20,00,25,00,2a,00,00,00

[HKEY_CLASSES_ROOT\ShellFile\ShellEx]

[HKEY_CLASSES_ROOT\ShellFile\ShellEx\DropHandler]
@="{86C86720-42A0-1069-A2E8-08002B30309D}"

The hex part actually is "C:\cygwin\bin\bash.exe -c "source $0;read" %1 %*" which gets encoded in the export.

You probably will want to remove the read after testing, so you can write scripts that just perform a task without leaving an open window. If you need this for single scripts, you can always add it add their end.

Use assoc .ext=ShellFile after importing to link any file extension you want with this functionality. The DropHandler in this example works for Windows XP and Windows 7 (probably others too) and basically means "run the command, with all dropped filenames as arguments".

Use this as a script (echotest.ext) to test basic functionality:

echo $0 $*;

Solution 2:

Here is how to pass an argument to a bash shell function via SendTo (or via drag & drop). As an example I used the builtin echo. Set the target for your link in the SendTo folder as follows:

C:\cygwin\bin\bash.exe -c "echo Argument: $0; read"

Here $0 stands for the first argument after the given command linea), i.e. the full filename of the file on which the sendto action was executed. read keeps the window open, so that you can read the message. (I tested this with cygwin's bash, but I think mingw's bash should work, too.)

In your case, the target should be

c:\MinGW\msys\1.0\bin\bash.exe -c "/path/to/your/script.sh $0; read"

Now your script can process the filename. But note, that the filename is passed to the script as the first argument, so inside the script the filename is referenced as $1.


Last, but not least here are two screenshots as a summary:

enter image description here


enter image description here


a) You quoted man bash:

-c string If the -c option is present, then commands are read from string. If there are arguments after the string, they are assigned to the positional parameters, starting with $0.

To understand that, use e.g. the following target line:

C:\cygwin\bin\bash.exe -c "echo This is $0; read" Foo Bar Baz

This will print This is Foo, while

C:\cygwin\bin\bash.exe -c "echo This is $2; read" Foo Bar Baz

will print This is Baz. So the "string" is everything between the apostrophes, and Foo Bar Baz are the arguments.