启用将文件拖放到 Ruby 脚本 [英] Enable dropping a file onto a Ruby script

查看:19
本文介绍了启用将文件拖放到 Ruby 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个小的 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 依赖于操作系统(如果是 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 集成的另一种简单方法是使用您希望出现在 Windows 资源管理器上下文菜单中的命令写入注册表项 HKLMSoftwareClasses*.jpgmyhandlercommand(右键单击 jpg 文件将弹出一个菜单,其中包含您的脚本).

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

我不使用拖动 &在 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆