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

bashsend-toshellwindows 7

I would like to use a bash shell script from the SendTo folder. When I put a shortcut to a batch or exe into theSendTo folder it shows up in the shell Send To context submenu, but when the shortcut is pointing at a shell script it doesn't.

The OS I'm testing this on is Win7 Home Premium SP1. The extension is .sh which has been associated with MinGW's bash.exe.

My shell script has a .sh extension and I've tried disassociated the .sh extension (I think that MinGW set it up initially, but that didn't work) using this utility and tried to reassociate it to bash using:

ftype ShellScript=c:\MinGW\msys\1.0\bin\bash.exe -c "'%1' %2"
assoc .sh=ShellScript

in an admin cmd shell. Though this works at a command prompt and the Explorer shell (via double click), it won't show up in the Send To menu and it won't accept a parameter by dragging a file on top of the script directly.

Does anyone know how I would do this?

Best Answer

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 $*;
Related Question