0

I am trying to focus an application by it's PID.

I am using the function SetFrontProcess. This function requires a ProcessSerialNumber, I get this by passing the PID to GetProcessForPID. This works fine in OS X10.9, however the docs say it was deprecated in 10.9, is this true? If it is true why does it still work? Does it work in 10.10? I would love to continue using it.

Blagoh
  • 1,225
  • 1
  • 14
  • 29

1 Answers1

2

SetFrontProcess is part of the Carbon API. Most of it has been deprecated since 10.8, and it's not available at all on 64-bit. It's still available for 32-bit applications, but it's certainly not something you'll want to use for new code.

Use the Cocoa NSRunningApplication object as a substitute.

Community
  • 1
  • 1
  • Thanks dusk. Until what version can we guarntee it fully works? Like from what version osx should i not use it? I am shooting to support older version os osx too. Do you think osx 10.7 and up i should use Cocoa, and in 10.6 and less SetFrontProcess is fully supported? – Blagoh Feb 19 '15 at 21:31
  • 1
    The NSRunningApplication object has been available and fully supported since Mac OS X 10.6. There's no reason to use SetFrontProcess unless you need to support *really old* versions of the OS. (And even for that, there'd be a lot more work necessary; you'd have to build a PowerPC application, for one…) –  Feb 19 '15 at 21:42
  • Got it! Thanks dusk! Im looking to just support 10.5 at minimum. – Blagoh Feb 19 '15 at 22:23
  • The `SetFrontProcess` family of functions support 64-Bit, otherwise I don't think you'd be able to compile 64-Bit apps, I may be wrong though. Either way until Apple actually removes those functions I don't see a reason to switch to the NS* flavor. In fact I'd be surprised if they bother removing them at all. But again this is very project dependent, I prefer the C call, your mileage may vary. – Dave Mar 18 '15 at 06:20