/ Published in: Ruby
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#!c:/ruby/bin/rubyw.exe require 'win32ole' require 'timeout' filename = ENV['TM_FILEPATH'].chomp.gsub(/\\/, '/').capitalize url = "file:///" + filename # Methods def openNewBrowser(url) begin Timeout::timeout(5) { ie = WIN32OLE.new('InternetExplorer.Application') ie.Navigate("#{url}") sleep('.2'.to_f) while ie.ReadyState != 4 ie.Visible = 'true' } rescue Timeout::Error puts "Unable connect to #{url} in a reasonable time" end end def refreshIfOpen(url) shell = WIN32OLE.new('Shell.Application') shell.Windows.each do | window | if window.LocationUrl == "#{url}" window.refresh() return true end end return false end # Main unless refreshIfOpen(url) openNewBrowser(url) end