[OS X] OpenUrl() Broken (with fix)

Archives Forums/BlitzMax Bug Reports/[OS X] OpenUrl() Broken (with fix)

SebHoll(Posted 2010) [#1]
OpenURL() doesn't work when specified a folder (visible from MaxIDE, when you right click a project node folder and choose 'Explore'). I think we may be overcomplicating this - the 'open' command that ships on all Macs sorts out all of the hard work for us. You pass it a string, and it opens the folder in finder if its a directory, opens the URL in the default browser if its a link, or open the file (as if double clicking it) if its a file path.

brl.mod/system.mod/system.macos.bmx's TMacOSSystemDriver.OpenUrl() can simply be:

	Method OpenURL( url$ )
		Return system_( "open "" + url.Replace("~q","") + "~q" )
	End Method
Don't forget to add an Import Pub.StdC to the top so that it will compile. This also makes bbOpenUrl() in system.macos.m redundant, so could be removed if so desired.

If this could be implemented in the next release, it would make the Mac implementation as flexible as the Windows implementation (hopefully :P).

Cheers!


marksibly(Posted 2010) [#2]
Hi,

Doesn't compile as is - I assume it's supposed to be:

Return system_( "open ~q" + url.Replace("~q","") + "~q" )

Also, what about URL's with quotes in them? I thought quote was a valid URL character.

Also, what about the 'stringByAddingPercentEscapesUsingEncoding' call currently in bbOpenURL? Seems like it might be important...


SebHoll(Posted 2010) [#3]
Doesn't compile as is - I assume it's supposed to be:

Return system_( "open ~q" + url.Replace("~q","") + "~q" )

Yep, that's the one. I swapped from single quotes to double quotes after posting, as it makes a lot more sense. Sorry... :-)

Also, what about URLs with quotes in them? I thought quote was a valid URL character.

Quotes should be encoded using "%blah", as far as I understand it.

See the RFC pointed to here.

Also, what about the 'stringByAddingPercentEscapesUsingEncoding' call currently in bbOpenURL? Seems like it might be important..

I figured this was to correct broken URLs that were passed in and not properly encoded. In my opinion, apps should know to encode their URLs properly. AFAIK, Windows' ShellExecute doesn't check URLs for valid characters, and it could be argued that Mac's implementation shouldn't either. Maybe if OpenUrl() was designed specifically for URLs, then it might be a nice thing to add, but as it's a multi-function for also opening documents and executables too, I would argue its expecting a bit too much from this multi-purpose command.


marksibly(Posted 2010) [#4]
Hi,

So stringByAddingPercentEscapesUsingEncoding should take care of the quote issue?

I vaguely remember adding it due to a user request in the first place - removing it to accomodate a different user's request (ie: yours!) feels a bit self-defeating.

Will have a go at whipping up our own version of the above anyway...


marksibly(Posted 2010) [#5]
Hi,

Actually, it sort of IS working with folders.

All is fine on 10.4 anyway, but on 10.5 the finder window needs to have been open or you have to manually click on finder yourself.

Investigating further...


marksibly(Posted 2010) [#6]
Hi,

Ok, that's wrong.

Works OK on 10.4, definitely borked on 10.6...


marksibly(Posted 2010) [#7]
Ha,

This is fun:

'system open' works with URL dir's (eg: file:/users/blah) only on 10.6

'workspace.openUrl' works with URL dir's only on 10.4!


SebHoll(Posted 2010) [#8]
Typical :-/ . Gotta love OS X's point release differences...

Have you experimented with the "Show In Finder" flag (check the man page for 'open')?