• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: 2 problems.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 2 problems.


  • Subject: Re: 2 problems.
  • From: Dan Saul <email@hidden>
  • Date: Mon, 3 Jan 2005 13:37:12 -0600

http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/ObjC_classic/Classes/NSWorkspace.html#//apple_ref/doc/uid/20000391/BCIEGAJI

Dictionary contains information described in the constants:

http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/ObjC_classic/Classes/NSWorkspace.html#//apple_ref/doc/uid/20000391/BCIEEFBI

Notably @"NSApplicationProcessIdentifier" The application's process
id, as an NSNumber.

Read the documentation (NSString) on how to load a text file into a NSString.

Use -componentsSeparatedByString:@"\n" to separate each line.
http://developer.apple.com/documentation/Cocoa/Reference/Foundation/ObjC_classic/Classes/NSString.html#//apple_ref/doc/uid/20000154/componentsSeparatedByString_

Use a for() to enumerate through every element of the array (each line).

use -rangeOfString to see if that line has what you want ie if
([aString rangeOfString:@"WEBSERVER"].location != NSNotFound) .

http://developer.apple.com/documentation/Cocoa/Reference/Foundation/ObjC_classic/Classes/NSString.html#//apple_ref/doc/uid/20000154/rangeOfString_

and replace that element in the array with the new changed one (this
will have to be a mutable array).

http://developer.apple.com/documentation/Cocoa/Reference/Foundation/ObjC_classic/Classes/NSMutableArray.html#//apple_ref/doc/uid/20000138/BABBBECB

and recreate the string with -componentsJoinedByString:

http://developer.apple.com/documentation/Cocoa/Reference/Foundation/ObjC_classic/Classes/NSArray.html#//apple_ref/doc/uid/20000137/BABDECEE

Then write that string to file, you may have to write to a temp file
then launch a sub dæmon to ask for admin privs to copy the file.

But I don't know how to do that.

Since you don't have much time I provided you links to the sections of
the manuals, hopefully next time you won't need a map to get what is
needed done, most other people on the list would shrug this off.

RTFM is just that easy :) .

PS. Make sure you reply to all to make sure everyone on the list gets
it (notably email@hidden).

- Dan

On Mon, 3 Jan 2005 04:19:46 -0500, D. Walsh <email@hidden> wrote:
>
> On Jan 03, 2005, at 00:31, Dan Saul wrote:
>
> > To find if a application is running, use -launchedApplications in
> > NSWorkspace.
>
> can you provide me with some source for the info you mention above?
>
> > I am not too familiar with shell scripting else seems to be able to be
> > done with NSFileManager and NSString calling system() or popen() if
> > you must.
>
> do you have some source code opens a text file and can do what is
> described in the shell script below???
>
> all I need to do is open the file, look for the string defined in
> "NAME", set it to "-YES-" or "-NO-" (look in /etc/hostconfig for
> example of entries)
> if the entry doesn't exist it gets added.
>
> > But these really are RTFM questions, take a look on
> > http://cocoadev.com if you need more reference tools.
>
> While RTFM will eventually get done,I don't have the time to educate
> myself quickly so I can write the required routine which is why I
> asked, time is critical, I need it now.
>
> The source for MySQL Manager would have saved me a lot of work cause I
> could have modified it and changed the daemon name to my daemon instead
> of the mysql daemon and set it to make the change in hostconfig for my
> settings instead of "MYSQL=-YES-" or "MYSQL=-NO-".
>
> >
> > On Mon, 3 Jan 2005 00:11:47 -0500, D.Walsh <email@hidden>
> > wrote:
> >>
> >> I realize this may be newbie type questions or questions from an
> >> inexperienced programmer but, all that I ask is that you please stop
> >> laughing long enough to provide me with a useable answer that doesn't
> >> include RTFM or go search.
> >>
> >> problem #1
> >>
> >> I have the following shell script, valid values for VALUE are '-YES-'
> >> or '-NO-'
> >>
> >> #!/bin/sh
> >>
> >> NAME="MAILTRANSPORT"
> >> VALUE=$1
> >> PATTERN="^$NAME="
> >> HOSTCONFIG=/etc/hostconfig
> >>
> >> if [ -z $(grep "$PATTERN" $HOSTCONFIG) ]; then
> >>      # create initial entry
> >>      echo "$NAME=$VALUE" >> $HOSTCONFIG
> >> else
> >>      # replace entry with new value
> >>      TMP=$(mktemp /tmp/hostconfig.XXXXXX) || exit 1
> >>      grep -v "$PATTERN" $HOSTCONFIG >> $TMP
> >>      echo "$NAME=$VALUE" >> $TMP
> >>
> >>      mv $TMP $HOSTCONFIG
> >>      chmod 644 $HOSTCONFIG
> >>      chown root:wheel $HOSTCONFIG
> >> fi
> >>
> >> I need to duplicate this process in a binary application (made in
> >> XCode) so I'm looking for some source code that does this, do you have
> >> something that can help me?
> >>
> >> problem #2
> >>
> >> How do I determine if an application/daemon is running, the app/daemon
> >> has a pid and a socket file, if you have some source code for this I'd
> >> appreciate it.
> >>
> >> -- Dale
>
>
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: 2 problems.
      • From: Dan Saul <email@hidden>
References: 
 >2 problems. (From: "D.Walsh" <email@hidden>)
 >Re: 2 problems. (From: Dan Saul <email@hidden>)

  • Prev by Date: Re: Invisible characters in NSTextView
  • Next by Date: Re: 2 problems.
  • Previous by thread: Re: 2 problems.
  • Next by thread: Re: 2 problems.
  • Index(es):
    • Date
    • Thread