ruby - 在 Windows 中右键单击并选择 Ruby 的上下文菜单选项

标签 ruby windows contextmenu

如何在简单的脚本中告诉 Ruby 右键单击​​ Windows 文件夹中的文件并从上下文菜单中选择一个选项?

最佳答案

使用 win32utils,您可以避免使用 API 调用将链接发送到桌面:

require 'win32/shortcut'
require 'win32/dir'
include Win32

Shortcut.new(Dir::DESKTOP + '\shortcut.lnk') do |s|
  s.path = "c:\\path\\to\\something.exe"
  s.window_style = Shortcut::SHOWNORMAL
  s.description = "My shortcut to something"
end

您需要 win32-shortcutwin32-dir gem;您还需要确定提供给 Shortcut#path 的文件路径。这通常可以使用 Dir#each 轻松完成,将您感兴趣的目录传递给它,并对您迭代的目录元素进行某种控制。

关于ruby - 在 Windows 中右键单击并选择 Ruby 的上下文菜单选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10435094/

相关文章:

java - Bouncy CaSTLe 无法在 Linux 机器上运行

asp.net-mvc - 无法安装 Asp.net MVC 3

jquery - 动态驱动器上下文菜单脚本破坏了 jQuery

wpf - 如何自定义默认上下文菜单

mysql - 如何使用 Tire 从 Elasticsearch 索引中获取数据而不访问数据库

ruby-on-rails - Rails 5 - 带路由的嵌套 Controller

ruby-on-rails - Ruby on Rails 中的嵌套评论和回复

windows - 使用 git 和 tortoisegit 在 Windows XP 上验证失败

javascript - 为什么上下文菜单有时不起作用?

ruby - gem date_validator 不工作 Ruby 1.9.3 Rails 3.2.1