【问题标题】:Open browser with URL in Ruby在 Ruby 中使用 URL 打开浏览器
【发布时间】:2014-12-16 19:55:33
【问题描述】:

我一直在使用以下命令在 OS X 中启动默认浏览器:

system('open', url)

在升级到 Yosemite 之前,它一直运行良好。现在,我在尝试打开各种 URL 时经常收到此消息:

LSOpenURLsWithRole() failed with error -1712 for the URL http://blah.com

但有时该 URL 会起作用。我可以尝试一次,它会工作,另一个它可能不会。非常不可预测。

我已经尝试了所有这些:

system("open #{url}")
`open #{url}`
Launchy.open(url, debug: true)

Launchy.open( "#{ url }" ) do |exception|
  puts "Attempted to open #{url} and failed because #{exception}"
end

但它们都表现出相同的行为。一次打开多个 URL,如下所示:

urls.each do |url|
  system("open #{url}")
end

如何使用 ruby​​ 在 OS X 上的浏览​​器中持续打开特定 URL?

【问题讨论】:

    标签: ruby macos osx-yosemite


    【解决方案1】:

    您似乎同时推送了太多 url 的浏览器。

    使用sleep 似乎工作正常。

    15.times {|i| `open http://google.com?q=#{i}` }
    # LSOpenURLsWithRole() failed with error -1712 for the URL http://google.com?q=5.
    # LSOpenURLsWithRole() failed with error -1712 for the URL http://google.com?q=6.
    # LSOpenURLsWithRole() failed with error -1712 for the URL http://google.com?q=12.
    # LSOpenURLsWithRole() failed with error -1712 for the URL http://google.com?q=14.
    # => 15
    15.times {|i| sleep(0.2); `open http://google.com?q=#{i}` }
    # => 15
    

    【讨论】:

      猜你喜欢
      • 2020-05-27
      • 1970-01-01
      • 2010-09-14
      • 2014-12-06
      • 2014-02-10
      • 2015-05-29
      • 2021-07-12
      • 1970-01-01
      • 2012-07-13
      相关资源
      最近更新 更多