Open URL on local disk
-
I've not found a way to use
UI.openURL()
to open a file on a local disk. Anyone done this? -
I haven't had any problems. do you have a code example?
-
Say you have a pdf help file in the same folder as the script
help=File.dirname(__FILE__)+"/Help.pdf"
Now use
UI.openURL(help)
or alternatively just hard code the 'help' variable
ashelp="C:/.../Help.pdf"
-
@cjthompson said:
...do you have a code example?
Hmmm. What's going on?
# /r2/open_st_help.rb require 'sketchup' help = "/r2/sketch_talk.html" file = File.new( help, 'r' ) arr = file.readlines() file.close() puts arr[0] puts UI.openURL( help )
The file reads correctly. (Eliminate typos in address constant.) But doesn't open:
-
A URL 'file' needs a full file-path, as used in a browser etc you need to add the Plugins folder path to the start of the rest of the path it uses ? Base Ruby manages without it ?
-
@tig said:
you need to add the Plugins folder path to the start of the rest of the path it uses ?
That file isn't in Plugins. It's in C:/r2/. Oddly, when I add "C:" to the location,
UI.openURL()
reportstrue
, but an open file in my default browser doesn't happen. -
Anyone?
-
UI.openURL()
Works fine for me with web-pages e.g.UI.openURL("http://www.google.com")
and with folders/files giving the absolute pathUI.openURL("C:/Program Files/Google/Google SketchUp 7/Plugins")
, add/myruby.rb
to open that file.
I think you have to pass it a string for the path that is a full-path with drive etc...
I have occasionally heard of similar problems, but sorry, I don't have a solution
Which of the above examples work for you ? -
Sounds like it expects an URL - not a file path. Have you tried prefixing with
file://
?
http://en.wikipedia.org/wiki/File_URI_scheme -
@thomthom said:
Sounds like it expects an URL - not a file path. Have you tried prefixing with
file://
?
http://en.wikipedia.org/wiki/File_URI_schemeIt will take a URL or absolute file path - you can then open folders, files and even applications...
TryUI.openURL("C:/Windows/System32/notepad.exe")
???
-
@tig said:
Try
UI.openURL("C:/Windows/System32/notepad.exe")
UI.openURL("notepad.exe")
or even justUI.openURL("notepad")
will also work. -
@cjthompson said:
even just
UI.openURL("notepad")
will also work.You never know when one little factoid will solve a problem.
I tried
notepad
(it works), thennotepad++
(also works) and then an HTML file. It opened the HTML, but it opened it in Notepad++.Now if only I can figure out how to specify both program and file ...
-
What is your default html opening program ? Notepad++.exe ?
-
@martinrinehart said:
It opened the HTML, but it opened it in Notepad++.
This a problem specific to your machine Martin, because you have overridden the HTML &Open file association to open in Notepad++ instead of leaving it pointing to your default browser (IExpore).
You should have instead had the &Edit association pointing to Notepad++, and left the &Open as it was.
So it is not a problem for your users... it's personal problem.
To 'fix' it, open Windows Explorer, any folder (doesn't matter.)
- On Menu: Tools > Folder Options...* In "Folder Options" dialog, choose "File Types" tab.* [Windows will take a few mins to build the list]* In list, (with 1st item selected,) click the "H" key to scroll down to the H extensions.* scroll a bit more to show HTM and HTML extensions* highlight each in turn, click the "Advanced" button* In "Edit File Type" dialog, highlight "Open"* If it's NOT set to default, the "Set Default" button will be enabled, so click it to restore normal htm/html broswer open.* If it's set to default, the "Set Default" button will be greyed (disabled,) and it's properly set.I'm not sure if you will need to log off, and back on to see changes reflected.
-
@dan rathbun said:
You should have instead had the &Edit association pointing to Notepad++
Folder Options has disabled what I need:
I gave the user admin privileges, but that didn't help. I right-clicked in Explorer, Properties, and was able to change the default Open to a browser, getting
openURL()
working but that doesn't allow setting the Edit default.Can I go back to KDE now?
-
Just to make sure we aren't all going insane: what happens when you double click a .htm file?
-
I've set single click to open. An HTM opens in Chrome.
-
@martinrinehart said:
Folder Options has disabled what I need:
I gave the user admin privileges, but that didn't help.You can try going to Control Panel and right-click "Folder Options" and choose "Run As...", then pick an Administrative account to run this one applet as. (This is called running with "Elevated Privileges" in 'MS MicroSpeak'; and is more secure than having a user account always running with Administrative rights. Those slimeballs who write Trojans love people who always run with Administrative rights, especially when when connected to the Internet.)
Also there is a wizard for controlling browser setings called "Set Program Access and Defaults", if you can find it on the Start Menu, you can also right-click it's icon and "Run As..."
(It's actually a sub-routine of "Add/Remove Programs" and appears as the bottom button in it's left toolcolumn.) The program to run, if you have to actually right-click the file, in order to "Run As...", is:
%SystemRoot%\system32\appwiz.cpl
The shortcut command (in case you can't find it in your menus, and want to make a shourtcut,) is:
%SystemRoot%\system32\control.exe appwiz.cpl,,3 -
@martinrinehart said:
Now if only I can figure out how to specify both program and file ...
Something like this (needs work for Mac, and can be wrapped in a method.)
filename='somefile.html' path='C;/dir/dir' filepath=File.join(path,filename) if RUBY_PLATFORM.include?('mswin') # if Kernel.test(?d,"#{ENV['SystemRoot']}/ie9") browser="#{ENV['SystemRoot']}/ie9/iexplore.exe") elsif Kernel.test(?d,"#{ENV['SystemRoot']}/ie8") browser="#{ENV['SystemRoot']}/ie8/iexplore.exe") elsif Kernel.test(?d,"#{ENV['SystemRoot']}/ie7") browser="#{ENV['SystemRoot']}/ie7/iexplore.exe") elsif Kernel.test(?d,"#{ENV['SystemRoot']}/ie6") browser="#{ENV['SystemRoot']}/ie6/iexplore.exe") elsif Kernel.test(?d,"#{ENV['SystemRoot']}/ie5") browser="#{ENV['SystemRoot']}/ie5/iexplore.exe") else raise(Errno;;ENOENT,filepath) end # else # Mac # browser = ??? end # open specific file in broswer f = IO.popen("#{browser} #{filepath}")
EDIT: It looks like the PC browser location (for all versions) can be simplified to:
browser = "#{ENV['ProgramFiles']}"<<'/Internet Explorer/iexplore.exe'
It may be that the hidden system folder "Windows/ieX" is a install folder. -
@martinrinehart said:
I've set single click to open. An HTM opens in Chrome.
Hey Martin, what's the fullpath to the Chrome executable on your PC ??
Advertisement