Detect Firefox from current Mac box (code ready)

Discussion in 'Apple' started by justaguy, Dec 10, 2011.

  1. justaguy

    justaguy Guest

    With the help of this ng, I've come up with the following code to
    detect if the current Mac computer has Firefox browser installed
    already but because I don't have a Mac myself, it would you be very
    helpful if you could copy/paste and save the following code a shell
    script and run it and then tell me know outcome including Firefox
    browser installation status with your Mac. Not shooting for
    perfection if it works with 90% of average Mac users it's good
    enough. Thanks in advance.

    if ! [mdfind -name]; then
    echo "Firefox browser is required for Knowledge NoteBook"

    # why not providing the else scenario? Just move on to next task...
    justaguy, Dec 10, 2011
    1. Advertisements

  2. It doesn't work at all.

    First, your syntax is totally broken (so not only don't you know
    anything about Macs, you also don't know basic shell scripting). You
    don't use [ ] when running a command, you use it to perform arithmetic
    or string comparisons. And when you use it, you need to pur spaces
    around them -- "[" is the name of a command, it's not shell syntax.

    Second, mdfind doesn't set its exit status, it just prints output, so it
    can't be used directly in an "if" command. You need to capture the
    output and see if it's empty.

    Third, even with Firefox installed, mdfind -name doesn't
    return anything, but mdfind -name Firefox finds lots of files.
    Apparently mdfind doesn't include the suffix when searching.

    But then there's problem that it will find anything with Firefox in its
    name, even if you don't have the application installed. For instance,
    it found some files in my Safari cache. You can use the -onlyin option
    to limit its search to /Applications, though.

    Here's a version that should work:

    if [ -z "$(mdfind -onlyin /Applications -name Firefox)" ]
    then echo "Firefox browser is required for Knowledge Notebook"
    exit 1
    Barry Margolin, Dec 10, 2011
    1. Advertisements

  3. justaguy

    justaguy Guest

    Excellent, thank you.
    justaguy, Dec 10, 2011
  4. justaguy

    justaguy Guest

    You're trying to create a 99.9999% reliable installer, that takes much
    more effort to do, and not my top priority, I told you BEFORE.

    And using -onlyin /Applications assumes the user placed the Firefox
    application in the /Applications folder, and not somewhere else,
    may be the case for a lot of Mac users.
    Virtually every program has a default installation directory/folder...
    over 90% users would go for default. So, BM's code would work for 90+
    % users, for the rest Mac Firefox users, screw you!

    It seems like if you are simply trying to verify that an application
    exists on a system, it would be better to find the actual
    regardless of the file name, and no matter where it is on the system.
    As I said before, the trick is to search for the application's bundle

    mdfind 'kMDItemCFBundleIdentifier == "org.mozilla.firefox"'
    All right, if we get quite a bit of false positive I'll switch to your
    code, MIND your language tho.

    # maybe more accurate version
    if ! [ mdfind 'kMDItemCFBundleIdentifier == "org.mozilla.firefox"' ]
    echo "Firefox browser is required for Knowledge Notebook"
    exit 1
    justaguy, Dec 10, 2011
  5. Because he's obviously committed to doing things his way. We can't
    break him of that notion, so the best I can do is fix his syntax.
    It seems like his app is for a limited audience, and he said he wasn't
    interested in covering all bases.
    I'm not sure what the point of that is. When you launch an app, you
    don't usually give the path, you let the system find it.
    Barry Margolin, Dec 10, 2011
  6. justaguy

    Warren Oates Guest

    See, I used to strive for 100% reliability. I know that's probably not
    possible (especially with me), but it's something to strive for. Srsly.
    Warren Oates, Dec 10, 2011
  7. Barry _is_ helping him. Just enough to produce an install that will (a)
    refuse to run if Firefox isn't installed (2) check for Firefox only in
    /Applications (3) work only in a command-line window.

    Michael Vilain, Dec 10, 2011
  8. Barry, I think JR's point is that some people have applications on their
    systems in places other than /Applications. I put a bunch of
    web-related applications I don't use very often in

    /Users/Shared/Archive/web stuff

    If I also put little-used browsers there, his code wouldn't find Firefox
    but JR's would. If the OP doesn't care (indeed, he's requiring Firefox
    to install his application and wants to modify /etc/rc.common to install
    that), then I see your point.

    I think the fun conversation will come when he wants to port something
    to the iPhone. This happened at a medical information services company
    that my friend was working for. Since they would only give him a PC to
    work on, he brought in his Macbook to do Java development. They asked
    about porting to the iPhone. He said "Buy an iPhone and Mac". They
    sprang for the iPhone and pointed to the PC before he told them that the
    development environment only ran on MacOS. I think they took the iPhone
    Michael Vilain, Dec 10, 2011
  9. I understand that. I wasn't responding to the part about apps installed
    in nonstandard directories, I was responding to the part where he
    suggested popping up a menu to select one of many locations.
    Barry Margolin, Dec 10, 2011
  10. justaguy

    Wes Groleau Guest

    He finally makes his attitude problem explicit.
    Wes Groleau, Dec 11, 2011
  11. justaguy

    justaguy Guest

    No, you misunderstood. Average users would choose default
    installation for Firefox and other programs as well, and for those
    doing it their own way (customization etc.) are smarter and pickier
    (harder to please), having them as your user/customers may not prove
    very sensible business-wise... It's just that I'm at liberty with
    language all the time...
    justaguy, Dec 11, 2011
  12. justaguy

    justaguy Guest

    justaguy, Dec 11, 2011
  13. justaguy

    Warren Oates Guest

    I love it when they kook out. Can I have a warning too? Please?
    Warren Oates, Dec 11, 2011
  14. **** off, troll. BTW, JR may be an SOB, but he's definitely not a bitch.
    I, on the other hand, am a bitch, but only when I want to be one. And I
    want to be one now.

    So what are you going to do, asshole, with your last warning? What
    consequences will JR (and probably I) face? Or are you just making empty
    threats to do along with your empty software?

    So what are you going to do, fuckwit? Huh?

    That's what I thought; you're going to do nothing.
    Michelle Steiner, Dec 11, 2011
  15. I love it when they kook out. Can I have a warning too? Please?[/QUOTE]

    get in line, Warren.
    Michelle Steiner, Dec 11, 2011
  16. Please, Sir, can you tell us what these consequences might be?
    And, Mon. Oates: YOU HAVE BEEN WARNED!
    John McWilliams, Dec 11, 2011
  17. justaguy

    Warren Oates Guest

    Thank you thank you. This is going to be the best Christmas ever!
    Warren Oates, Dec 12, 2011
  18. LOL thanks Michelle. I think.[/QUOTE]

    Yup, you're an SOB the same way I'm a bitch; you turn it on when you want

    And don't talk to me about getting older; I "celebrated" my 69th birthday
    on the first of this month.
    Michelle Steiner, Dec 12, 2011
  19. justaguy

    Wes Groleau Guest

    Burning your bridges wasn't fast enough, so you decided to use
    explosives? oops, I mean expletives...

    Better watch your back, JR. Li Chunshen knows people at
    AOL, Boeing, Booz.Allen, and BlueCross/BlueShield.

    Wes Groleau

    “If it wasn't for that blasted back-hoe,
    a hundred of us could be working with shovelsâ€
    “Yeah, and if it weren't for our shovels,
    a thousand of us could be working with spoons."
    Wes Groleau, Dec 12, 2011
  20. (some portions omitted to confuse the guilty)
    David Ryeburn, Dec 12, 2011
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.