openURL broken on MAC

Thanks for the observations, Dan.
Will take them into account.

1 Like

Hmm… not sure…

What type of docs? Do you have an example of how you have launced documents? (and what type of documents?)

The Windows version never auto-encoded the given URL, and we’d never heard any questions and complains about that. Given that an Windows is 90% of our userbase we felt confident at the time wasn’t a big problem. We do understand though that changes are frustrating and try to keep things working whenever possible. In this case the encoding Mac performed had problems of it’s own in that it would encode important characters such as #.

That’s not particularly constructive Barry. Keep it civil - no need to get personal.

3 Likes

I’m using it to open external SketchUp files in my reference manger and I’ve worked on extensions using it for opening PDF manuals. I used it just the other day to open .layout files generated by the SketchUp Ruby Layout API. Not sure if I’ve used it more but those are the things I can remember on the top of my head.

Can you provide a small snippet for what doesn’t work any more?

I don’t use Mac myself but this is what a user reported and how I followed up Eneroth Reference Manager - #32 by Early_Hominid.

1 Like

I also found this other thread on the topic - following up there.

In my case I believe it now fails because of underscore characters in folder or file names.
But I have no MAC I can use to test.

Hm… I didn’t think underscore was a special URI character.

If you have a little snippet I can try for you on the mac machine I have.

I am on vacation this week with only a smart phone. Will provide snippet next week.

1 Like

Next week is the Christmas holidays, I think most of the office is shut down - I certainly will be offline until after the new year.

Here is my snippet:

module TWODXY_SlickMoves
def self.help
#called by Toolbar

	help = File.join(File.dirname(__FILE__), '2DXY_SlickMoves.htm')
	puts "file:///#{help}"
	UI.openURL("file:///#{help}")
	
Sketchup.send_action "selectSelectionTool:"
end
	#test
#self.help
end # module

The .htm file is in the same folder as help.rb.
The full path returned is:
file:///C:/Users/Barry/AppData/Roaming/SketchUp/SketchUp 2017/SketchUp/Plugins/2DXY_SlickMoves/2DXY_SlickMoves.htm

The final subfolder and the htm file both have a single underscore.
Everything else is controlled by SketchUp except the username (in my case “Barry”).
I don’t know what characters MAC’s allow in usernames.

I’m hoping that whatever platform specific logic is needed to fix this can be included in a revised openURL method in version 19.4.

Thank you.

This will not happen. The method was purposefully changed to make it platform neutral.
This means any “platform specific logic” is the coder’s responsibility.

In addition, version 20 is due soon and there will be no more v19 releases.
Any fixes for any features that haven’t come this late in the year, will arrive (if they do) with some future version release.

This knowledge is also the coder’s responsibility.

On my phone now so I can’t test your code. But per the other discussions I can assure you that paths on macOS very frequently include spaces, and these must be encoded else openURL will fail. Underscore is not a reserved character so I think it should be fine. But ultimately the only safe course is to URI encode the path, which your snippet does not do.

One of my MAC users who now cannot see the help file reports that the full file path to the file is:
/Users/david/Library/Application Support/SketchUp 2019/SketchUp/Plugins/2DXY_SlickMoves/2DXY_SlickMoves.htm

  • Space before “2019”

I couldn’t disagree more. For an API to be platform neutral, it ideally hides as many platform differences from the developer as possible. And that is what the SU ruby API does. AND if a change like this situation is desired, the API author must maintain backward compatibility. The way to do that is to add a new recommended method “openURLnoencode”.

There is also a space in”Application Support”.

UI.openURL was broken on Mac up til SU2019.3. It worked in some simple scenarios - but prevented many valid URLs from being used.

For your example, this worked on both my Mac and Windows machine (SU2019.3):

require 'uri'

module Example
  def self.help
    path = File.join(__dir__, 'example.html')
    # SketchUp 2019.2 and older on macOS would encode the path given. Must avoid
    # double encoding for these versions.
    if !(Sketchup.platform == :platform_osx && Sketchup.version.to_f < 19.3)
      path = URI.encode(path)
    end
    UI.openURL("file:///#{path}")
  end
end # module

I find that URI.encode(help) does not work in SU 2017

However help.encode does

Also do these both work on a Mac (I don’t have one)
help = help.encode()
help = help.force_encode(“UTF-8”)

Can you elaborate on what doesn’t work? What do you observe and what do you expect?

These pertain to string encoding (UTF-8 etc, not URL encoding.) Not sure how these would relate this this… ?

I’m confused.
I thought the API openURL method before 19.3 used the same URI.encode method within it. Then in 19.3, they removed the URI.encode and require extension developers to invoke it.
Why would one approach work and not the other?