1

How would I use dscl in Objective-C and obtain its output? The command I want to pass as if it is in Terminal is:

dscl . -readall /Users UniqueID | awk '/^RecordName:/ {name=$2}; /^UniqueID: / {if ($2 > 500) print name}'

I know how to launch system_profiler with arguments such as -xml, etc. but I can't figure out how to pass such a long string in where is actually works.

I know system_profiler is /usr/sbin/system_profiler, but what about dscl?

sbooth
  • 16,646
  • 2
  • 55
  • 81
John
  • 3,037
  • 8
  • 36
  • 68

1 Answers1

1

Your best bet is to launch that as if it were a shell script. Either stick it in your project as a shell script in a file or use NSTask to compose a command line that invokes /bin/sh, passing the command as a string to allow sh to parse it.

I.e. /bin/sh -c ".... your command string ...."

bbum
  • 162,346
  • 23
  • 271
  • 359
  • Tried: outFileData =[taskLauncher launchTask: @"usr/sh" withArguments: [NSArray arrayWithObjects: @"-c", @"dscl . -readall /Users UniqueID | awk '/^RecordName:/ {name=$2}; /^UniqueID: / {if ($2 > 500) print name}'", nil]]; Didn't work – John Oct 09 '12 at 18:38
  • Tried: outFileData =[taskLauncher launchTask: @"bin/sh" withArguments: [NSArray arrayWithObjects: @"-c", @"dscl . -readall /Users UniqueID | awk '/^RecordName:/ {name=$2}; /^UniqueID: / {if ($2 > 500) print name}'", nil]]; and it didn't work. Also tried /user/bin/sh – John Oct 09 '12 at 21:46
  • 2
    Did you actually go to the Terminal window and try the command there? Clearly not. Do that; when you get it working in a Terminal, then copy/paste it into your code. (BTW: The answer is `/bin/sh`) – bbum Oct 09 '12 at 22:26