|
|
|
Ruby Win32 Drag and Drop
Ruby Win32 Drag and Drop is a Windows Explorer Drop Handler which allows
Ruby scripts to be executed by dragging and dropping either files or text onto
an .rb or .rbw file.
Example
Save the following Ruby script as test.rb
require 'Win32API'
Win32API.new('user32', 'MessageBox', 'LPPL', 'I').call(0, ARGF.read, '', 0)
Save the following text as data.txt
This is a test Now dragging and dropping data.txt onto test.rb, will result in a dialog
box saying "This is a test".
Similarly, selecting the text "Hello World" in an editor (Notepad, Word,
etc.) and dragging and dropping it onto test.rb generates a dialog box saying
"Hello World".
Details
Dragging and dropping the files "a.txt", "b.txt", and "c.txt" onto the file
"script.rb" runs rubyw as follows:
rubyw script.rb a.txt b.txt c.txt
Notes
- Actually, the command line contains the full paths to all the
script.rb, a.txt, b.txt, and c.txt files, each surrounded by double quotes
in case any of the directories has a space in it. I didn't show this above
for clarity.
- The dropped files appear in sorted order (sorted by full path, case insensitive). Ordinarily, the Windows shell provides the files names in a fairly random order. I felt sorting them made things slightly more
predictable.
- If text is dropped, a file is created in a temp directory to hold the text, and the path to this file is provided on the command line. Currently this file is not deleted, but it will be in a future version.
- rubyw is invoked whether the files or text are dropped on a .rb or a
.rbw file.
Installation
- Install Ruby using the One Click Installer.
- Copy the RubyDragAndDrop.dll file to anywhere. Sometimes files like
this are placed in 'c:/windows/system32', but it can go anywhere.
-
Start a Command Prompt window, cd to the directory containing
RubyDragAndDrop.dll, and run regsvr32:
C:\windows\system32>regsvr32 RubyDragAndDrop.dll
If this is successful, you'll see a dialog box saying
- You're all set. You shouldn't need to reboot Windows.
Prerequisities/Assumptions
- Microsoft's file msvcrt.dll must be installed. msvcrt.dll has been
included as part of the operating system since Win95 OSR2.
- I have tested this on NT4 SP6, Windows 2000, and Windows XP
Home and Professional. I expect it will work on Windows Server 2003 and on
Win95/98/ME, but I haven't been able to test this.
-
If you don't use the Ruby One Click Installer to install Ruby, you
need to ensure that at least two things are set up correctly:
-
The directory containing rubyw.exe must be in your path. You
can verify this by starting a Command Prompt window and
running "rubyw". If it's in your path you won't see an error
message:
C:\>rubyw
C:\>
- In the registry, the file extension .rb should map to rbFile,
and .rbw should map to rbwFile. You can verify this in RegEdit by
checking that the default value of the HKEY_CLASSES_ROOT/.rb
registry key is "rbFile" (and of .rbw is "rbwFile")
If there's sufficient interest I'll write up more detailed
instructions for getting this to work in a non-OneClickInstaller
environment.
Known Bugs and Limitations
- Temporary files created when text is dragged and dropped are never
deleted. (No temporaries are created when files are dragged and
dropped.)
- "regsvr32 -u RubyDragAndDrop.dll" does not work, and gets an
error.
Download
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Click to download RubyDragAndDrop.dll Version 0.5 Oct-2-2005
|