Enable dropping a file onto a Ruby script

后端 未结 4 1069
轮回少年
轮回少年 2020-12-18 11:34

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

4条回答
  •  孤城傲影
    2020-12-18 11:49

    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 .

提交回复
热议问题