Wrapping NSTask, setting PATH env var to current user's PATH...

  • Hi everyone,
    I'm wrapping command-line tools with NSTask (while getting a hang of
    Cocoa, so be gentle).
    I'm far more used to working at the command line and with Ruby in
    particular, but I'm not currently interested in RubyCocoa, more in
    learning Cocoa itself.
    I need some help here with setting the PATH environment variable of
    the NSTask process to the current user's PATH environment variable.
    Would this require some mucking around in the various dot-files in a
    user's home directory and
    reading .bash_login, .bashrc, .bash_profile, etc...?
    Or is there some stupid simple Cocoa method of getting the user's
    PATH setting and setting the NSTask's environment dictionary's PATH
    key's value?

    What I've currently got is a simple wrapper for the 'which' tool. I'm
    trying to use it for sanity checking for other tool wrappers, to
    check for the existence of tools on launch.
    In particular this will make it easy to ensure that the one found in
    the user's PATH (most likely version of a given tool that the user
    would expect to be used) is the tool that is used.

    I do have both of the Advanced OS X Programming book and have played
    with the Moriarity task wrapper app from ADC.

    Cheers,
    John Joyce
  • Thanks in advance for any replies.
    Looks like I finally found what I was looking for. Mostly it is a
    matter of doing some assuming on common PATH locations to search for
    and then set things up programatically. Looks like I will likely also
    need to programatically look for paths stored
    in .profile, .bash_login, etc... as part of life dealing with NSTask
    tools that may not be default OS X installed tools.

    I think my big stumbling block was switching my thinking from Ruby to
    Objective-C object messaging and method syntax. They're not terribly
    far apart conceptually, but the code does read a bit differently.
    The other stumbling block was simply getting used to Cocoa & Obj-C
    conventions and terminology for collections. Simply getting used to
    things like NSDictionary and the Cocoa/Obj-C way of KVC. In Ruby it's
    usually easy arrays and hashes.

    One thing I'm still kind of struggling to internalize is
    NSEnumerator. In Ruby, many classes inherit/mix in enumerating
    methods that are very common to its collection types of classes and
    become very core to the way things are very convenient there.
    Can anyone suggest a good tutorial/reference/example code on
    iterating with NSEnumerator and such in Cocoa? ( I hope I'm not
    asking in the wrong list here ).
  • On Jan 15, 2008 8:35 PM, John Joyce <dangerwillrobinsondanger...> wrote:
    > Thanks in advance for any replies.
    > Looks like I finally found what I was looking for. Mostly it is a
    > matter of doing some assuming on common PATH locations to search for
    > and then set things up programatically. Looks like I will likely also
    > need to programatically look for paths stored
    > in .profile, .bash_login, etc... as part of life dealing with NSTask
    > tools that may not be default OS X installed tools.
    >
    > I think my big stumbling block was switching my thinking from Ruby to
    > Objective-C object messaging and method syntax. They're not terribly
    > far apart conceptually, but the code does read a bit differently.
    > The other stumbling block was simply getting used to Cocoa & Obj-C
    > conventions and terminology for collections. Simply getting used to
    > things like NSDictionary and the Cocoa/Obj-C way of KVC. In Ruby it's
    > usually easy arrays and hashes.
    >
    > One thing I'm still kind of struggling to internalize is
    > NSEnumerator. In Ruby, many classes inherit/mix in enumerating
    > methods that are very common to its collection types of classes and
    > become very core to the way things are very convenient there.
    > Can anyone suggest a good tutorial/reference/example code on
    > iterating with NSEnumerator and such in Cocoa? ( I hope I'm not
    > asking in the wrong list here ).

    There isn't much to using NSEnumerator, as it's a very simple class.
    Just call -nextObject repeatedly. Each time you call it, you will be
    given a subsequent object in the collection being enumerated. When
    -nextObject returns nil, you know you've enumerated over the entire
    collection.

    NSEnumerator *enumerator = [someCollection objectEnumerator];
    id element;

    while(element = [enumerator nextObject]) {
      /*do something with element here*/
    }

    --
    Clark S. Cox III
    <clarkcox3...>
previous month january 2008 next month
MTWTFSS
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
Go to today