neddie Posted May 6, 2008 Share Posted May 6, 2008 (edited) I'm trying to find a way to launch a browser from a program, and it should work cross-platform, but unfortunately I haven't got a Mac to test it on. In Linux, what I do is this: - try to execute the command "which which". If this works, I know I've got the "which" command available, and I can use it to test for browsers. - If I've got which, I try a list of browsers in turn using which, so I call "which firefox", "which konqueror", "which safari" and so on (the list is longer than that). If I find one that gives success from the which command, I call that with a url, so for example "firefox http://mub.org" or whatever. So how would this work on a Mac? I know that Mac OSX is pretty much unix underneath the Applyness, so there must be a /usr/bin directory. But from what I've read, when an application is installed it doesn't really get installed as such but just put in /Applications or something. So there's no shortcut in /usr/bin for that application (depending on how it was installed of course). So what I'm trying to figure out is: - Will the command "which which" work? (I'm guessing yes if which is available everywhere then it must find itself) - Will the command "which firefox" work (or safari or whatever)? (I'm guessing that depends on where which can search for executables) - Will the command "firefox http://mub.org" work? Will it be able to find the firefox executable from any directory or does it need the whole explicit path? I'm guessing that the effect of running those commands from a console at ~ would be the same as running them from another program. Anyone with a Mac feel like trying them out for me please??? Edited May 7, 2008 by neddie Link to comment Share on other sites More sharing options...
paul Posted May 7, 2008 Share Posted May 7, 2008 open https://mandrivausers.org Opens the default http:// handler Link to comment Share on other sites More sharing options...
neddie Posted May 7, 2008 Author Share Posted May 7, 2008 Thanks paul, So does that mean that the method I described will not work for Macs? What would it do? And how do I figure out if I should use "open", cos that doesn't work on Linux but "which open" still returns a positive on Linux and says "start a program on a new virtual terminal". :unsure: I don't want separate code for Mac and Linux, and I'd prefer to do the checking without trying to retrieve and parse the OS name if possible - ie by checking for functionality instead. Link to comment Share on other sites More sharing options...
theYinYeti Posted May 7, 2008 Share Posted May 7, 2008 Wouldn't "xdg-open" be the right way to do that? But does it exist on a mac? Yves. Link to comment Share on other sites More sharing options...
paul Posted May 7, 2008 Share Posted May 7, 2008 xdg-open doesn't exist which doesn't exist you could try if [ `uname` == "Darwin" ] { open http:// } my uname -a on my g4 here gives: 8.11.0 Darwin Kernel Version 8.11.0: Wed Oct 10 18:26:00 PDT 2007; root:xnu-792.24.17~1/RELEASE_PPC Power Macintosh powerpc Link to comment Share on other sites More sharing options...
neddie Posted May 7, 2008 Author Share Posted May 7, 2008 you could tryif [ `uname` == "Darwin" ] { open http:// } That's exactly what I meant by "I'd prefer to do the checking without trying to retrieve and parse the OS name if possible" - just like the old days of browser detection and a new version comes out and the things stop working because the name isn't exactly like that any more... :( I was trying to detect which functions are available but maybe that's not possible? Link to comment Share on other sites More sharing options...
paul Posted May 7, 2008 Share Posted May 7, 2008 mmm thinking outside the square here :) [ -f /usr/bin/sw_vers ] { then do some grep'ing through the return result? eep:~ paul$ sw_vers ProductName: Mac OS X ProductVersion: 10.4.11 BuildVersion: 8S165 Link to comment Share on other sites More sharing options...
iphitus Posted May 7, 2008 Share Posted May 7, 2008 uname isn't going to change. Take linux for example, it's been "Linux" right from the start. This ain't web development :) Link to comment Share on other sites More sharing options...
neddie Posted May 7, 2008 Author Share Posted May 7, 2008 uname isn't going to change.Wow, very confident! I think I would be more confident if I had ever heard of Darwin before... but whatever. I was trying to avoid making assumptions that "name xyz implies function abc will be available, and anything else means it won't be", and trying to use a more reliable method of directly testing if the function is available.In that case it is exactly like browser detection! :P So does anyone know what the result of those 3 commands would be? which which which firefox firefox http://whatever Link to comment Share on other sites More sharing options...
paul Posted May 7, 2008 Share Posted May 7, 2008 eep:~ paul$ which which /usr/bin/which eep:~ paul$ which firefox no firefox in /bin /sbin /usr/bin /usr/sbin /usr/X11R6/bin eep:~ paul$ firefox http://whatever -bash: firefox: command not found eep:~ paul$ Link to comment Share on other sites More sharing options...
neddie Posted May 7, 2008 Author Share Posted May 7, 2008 Thanks! So some executables are in /usr/bin, but maybe just console apps. Interesting, thanks! Maybe I should launch lynx instead :D Link to comment Share on other sites More sharing options...
tyme Posted May 7, 2008 Share Posted May 7, 2008 (edited) I think I would be more confident if I had ever heard of Darwin before...Just for clarification purposes, Darwin is the Unix base (although largely FreeBSD-based) that OS X runs on. OS X keeps all of it's GUI applications (and some others) in /Applications/, and each one has it's own directory - though to a person using Finder to view applications, these directories would seem to be executables, as when you double click them the relevant application opens instead of the contents being revealed. This is also why the open command is used to start applications in /Applications/, because you don't really have access to a (binary?) executable (in the way you do with other OS's). Edited May 7, 2008 by tyme Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now