Enable dropping a file onto a Ruby script

后端 未结 4 1044
轮回少年
轮回少年 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 .

    0 讨论(0)
  • 2020-12-18 11:49

    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.

    0 讨论(0)
  • 2020-12-18 11:51

    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}"
    
    0 讨论(0)
  • 2020-12-18 11:57

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

    http://sveinbjorn.org/platypus

    regards Claus

    0 讨论(0)
提交回复
热议问题