Help - Search - Members - Calendar
Full Version: Mac question [solved]
MandrivaUsers.org > Advanced Topics > Other Linux and Unix Distributions
neddie
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???
paul
CODE
open http://mandrivausers.org


Opens the default http:// handler
neddie
Thanks paul, 2thumbsup.gif

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.gif

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.
theYinYeti
Wouldn't "xdg-open" be the right way to do that? But does it exist on a mac?

Yves.
paul
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
neddie
QUOTE (paul @ May 7 2008, 08:15 AM) *
you could try
if [ `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?
paul
mmm thinking outside the square here smile.gif

[ -f /usr/bin/sw_vers ]
{


then do some grep'ing through the return result?

CODE
eep:~ paul$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.4.11
BuildVersion:   8S165
iphitus
uname isn't going to change. Take linux for example, it's been "Linux" right from the start.

This ain't web development smile.gif
neddie
QUOTE (iphitus @ May 7 2008, 09:33 AM) *
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! tongue.gif

So does anyone know what the result of those 3 commands would be?
which which
which firefox
firefox http://whatever
paul
CODE
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$
neddie
Thanks! 2thumbsup.gif
So some executables are in /usr/bin, but maybe just console apps. Interesting, thanks!

Maybe I should launch lynx instead biggrin.gif
tyme
QUOTE (neddie @ May 7 2008, 05:03 AM) *
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).
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.