PDA

View Full Version : open URL in browser




McBgnr
Jun 1, 2009, 02:53 AM
Hello,

I am using the following code to open URL in the browser:

[[NSWorkspace sharedWorkspace] openURL:LinkURL];


I was assuming that this will open the URL in Safari, but I just realized that it opens the URL in default browser.

So now how can I open the URL in a specific browser say "FireFox" when it is not the default browser. We have the terminal command open -a to open file in specific browsers. So an option is to run the command using NSTask. Was just wondering if there is any other option to do so.

On another note, I am interested in knowing the place where Mac maintains the name of the default browser?



robbieduncan
Jun 1, 2009, 03:19 AM
The defaults for all documents/url schema are determined by Launch Services. There is an API for working directly with Launch Services (http://developer.apple.com/documentation/Carbon/Reference/LaunchServicesReference/index.html) if you have some specific need to, although I would steer clear if you can!

I would suggest that the openURLs:withAppBundleIdentifier:options:additionalEventParamDescriptor:launchIdentifiers: (http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSWorkspace_Class/Reference/Reference.html#//apple_ref/occ/instm/NSWorkspace/openURLs:withAppBundleIdentifier:options:additionalEventParamDescriptor:launchIdentifiers:) method of NSWorkspace could be used to open one (or more) URLs is a specific browser...

McBgnr
Jun 1, 2009, 03:50 AM
I was able to open URL in specified browser. Thanks a bunch for the helpful links.