Open generic file in Ruby

I’ve sometimes used UI.openURL to open a file on the local computer in its default program, and I’ve seen other extensions doing it to, e.g. a PDF manual. However it was brought to my attention last week this isn’t reliable on Mac. (Eneroth Reference Manager)

@john_drivenupthewall provided a good solution but it only applies to SketchUp files, not the general case.

Does this code work for e.g. opening a .layout file in LayOut?

path = UI.openpanel("Locate file")
if Sketchup.platform == :platform_win
  UI.openURL(path)
else
  system("open #{path.inspect}")
end
1 Like

Worked for me!

Thanks!

For the record I’m referencing similar thread: UI.openUrl( local_path ) doesn't work on Mac OSX

(Sounded like prefixing file:/// should also work cross platform with UI.openURL. But I haven’t confirmed this myself yet.)