views:

163

answers:

2

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

+1  A: 

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
+3  A: 

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