Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
524 views
in Technique[技术] by (71.8m points)

scripting - Enable dropping a file onto a Ruby script

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 HKLMSoftwareClasses*.jpgmyhandlercommand 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 .


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...