Jump to content

Mac question [solved]


Recommended Posts

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 by neddie
Link to comment
Share on other sites

Thanks paul, :thumbs:

 

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

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

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?

Link to comment
Share on other sites

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

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

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

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 by tyme
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...