启用将文件放入Ruby脚本 [英] Enable dropping a file onto a Ruby script
问题描述
我正在创建一个小的ruby脚本来调整图像大小并将它们保存在指定的目录中。我希望应用程序尽可能透明。
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.
是否可以允许在所有平台中的文件丢弃到我的Ruby脚本?例如,用户将文件拖放到脚本上,然后将文件路径作为参数,并相应地调整图像大小 - 无GUI,无控制台等。
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..
推荐答案
drop取决于操作系统(如果是Window Manager的Linux),所以没有。
The behavior of drag & drop is dependent on the OS (and in case of Linux of the Window Manager), so no.
在Windows中,您可以获得所需的行为。只需将一个.rb文件放在桌面上,拖动到这个文件上的文件将成为脚本的参数。
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.
与Windows集成的另一个简单方法是写入注册表条目HKLM\Software\Classes * .jpg\myhandler\command与你想显示在Windows资源管理器的上下文菜单中的命令(右键点击一个jpg文件将弹出一个菜单,这将有你的脚本在菜单中)。
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).
我不使用拖放在Linux中掉下来,所以我不知道该怎么做。我希望它有更多的安全问题(权限必须正确,...),但您可以通过创建.desktop文件到达那里,请参阅 http://standards.freedesktop.org/desktop-entry-spec/latest/ ,或从〜/ Desktop / *中读取一些示例。桌面。
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 .
这篇关于启用将文件放入Ruby脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!