27

Our OS X Java application which is launched by a shell script inside the MyApp.app bundle gets a strange command line parameter -psn_0_989382 when launched from the Finder, but not when launched directly from the Terminal. Where can I find information what this command line parameter is good for?

Mot
  • 28,248
  • 23
  • 84
  • 121
  • 1
    It also happens if you launch app via the `open` command. Interesting, that since 10.11 (or earlier?) this argument is only passed to the process on first launch. – Kentzo Nov 11 '15 at 18:08
  • 1
    I wonder why they chose to use a command line parameter for this, instead of an environment variable. Well, they might have had their reasons. – MvG Feb 11 '16 at 13:50
  • I experience this today and behavior is uncertain. I launched from Finder and observed MacOS _sometimes_ passes `-psn` and not always. I found it's very weird and uncertain behavior of MacOS. – Atul Feb 12 '20 at 02:37

2 Answers2

31

Mac OS X assigns a unique process serial number ("PSN") to all apps launched via GUI. It's used for identifying various processes and instances of executables.

There's nothing I can really add to the documentation, so the best thing is to read the ProcessSerialNumber section of the Carbon Process Manager Reference (original Apple link is dead; this is a mirror).

fzwo
  • 9,842
  • 3
  • 37
  • 57
inspector-g
  • 4,146
  • 2
  • 24
  • 33
  • Though I haven't tested it, I'm not surprised. It was bound to happen someday, as Apple has deprecated all of Carbon. (Since 2008 I think?) – inspector-g Apr 12 '18 at 03:01
  • 2
    @ToFi Still happens today on MacOS 10.13. – Matt Nov 03 '18 at 01:01
  • 3
    Today, on MacOS Mojave 10.14.5, this -psn_ parameter is not normally passed to an app, except the first time when you get the "App downloaded from the internet" warning, and you click the Open button. – O'Rooney Sep 18 '19 at 03:41
  • 1
    BTW this answer and the docs don't really mention why the magic parameter is passed or it's format. – O'Rooney Sep 18 '19 at 03:44
0

It seems that older applications that used the Carbon API get started with this argument. If the application was already updated to a version not using Carbon any more, you can unregister the application from the LaunchServices database by:

/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -u /Applications/AppName.app/

After this it can be re-launched from Finder to register the new version. Then it should not get this argument any more.