3

I'm creating a small ruby script to resize images and save them in a specified directory. I'd like the application to be as transparent as possible.

Is it possible to allow file dropping onto my Ruby script in all platforms? For instance, the user drags a file onto the script, which then takes the file path as an argument and resizes the image accordingly -- No GUI, no console, etc..

NolanDC
  • 1,041
  • 2
  • 12
  • 35

4 Answers4

5

The behavior of drag & drop is dependent on the OS (and in case of Linux of the Window Manager), so no.

In Windows, you get the behavior you want for free. Just put a .rb file on the Desktop, and the files dragged onto it will be arguments to your script.

Another easy way for integrating with Windows is to write to registry entry HKLM\Software\Classes*.jpg\myhandler\command with the command you want to appear in the context menu of Windows Explorer (right click on a jpg file will popup a menu which will have your script in the menu).

I don't use drag & drop at all in Linux, so I wouldn't know how to do that there. I would expect it to have more security issues (permissions must be right, ...) but you could get there by creating a .desktop file, see http://standards.freedesktop.org/desktop-entry-spec/latest/ for the complete standard, or read some examples from ~/Desktop/*.desktop .

Rutger Nijlunsing
  • 4,861
  • 1
  • 21
  • 24
  • 1
    in windows you need to edit the registry as i indiated in my answer before this will work – peter Apr 20 '14 at 13:34
2

Platform dependend, so here for windowsusers and reference only. Save the following to a .reg file and load it by doublecliking it, tested on Windows Vista and 7

Windows Registry Editor Version 5.00

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

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

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

[HKEY_CLASSES_ROOT\RubyWFile\ShellEx\DropHandler]
@="{86C86720-42A0-1069-A2E8-08002B30309D}"
peter
  • 41,770
  • 5
  • 64
  • 108
  • Note that if you installed Ruby via Cygwin, this might need registering the file manually first. The important part is setting the `\ShellEx\DropHandler` key's value. – rr- Jan 01 '15 at 09:44
1

Such behavior would surely be platform specific, as drag-and-drop is implemented by the OS in this case, not by ruby.

So answering your question: no, it is not possible.

Sinan Taifour
  • 10,521
  • 3
  • 33
  • 30
1

You can use platypus on os x to create a wrapper around your script.

http://sveinbjorn.org/platypus

regards Claus

kometen
  • 6,536
  • 6
  • 41
  • 51