Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>No need for a hideous regex to parse the output of <code>ps</code> – the <code>ps</code> utility already does what you ask of it. Calling it with the (admittedly somewhat arcane looking) following options</p> <pre class="lang-bsh prettyprint-override"><code>ps [-ww] -o comm= -p &lt;pid&gt; </code></pre> <p>will return the path to the executable belonging to your PID (the <code>-ww</code> argument is only needed if you output to a terminal, as <code>ps</code> will truncate the returned path without it. It should not be necessary otherwise).</p> <p>The problem with retrieving a bundle ID from there is that not all processes map to bundles with an Info.plist (which defines the bundle ID) – notably, *nix type executables are not bundles and thus have no bundle ID. Also, even in the case of app bundles, <code>ps</code> returns the core executable of an application, not the path to the bundle itself. As the path to the executable inside an application bundle is standardized, however (it resides in <code>Path.app/Contents/MacOS</code>), you can retrieve it with a bit of directory traversal.</p> <p>Assuming you have stored the output of the <code>ps</code> call above in the variable <code>execfile</code>, this</p> <pre class="lang-bsh prettyprint-override"><code>[[ ${execfile%/*} =~ ^.+/Contents/MacOS$ ]] &amp;&amp; defaults read "${execfile%/*/*}"/Info CFBundleIdentifier </code></pre> <p>will retrieve bundle identifiers for likely paths by using <code>defaults</code> to retrieve the value of the <code>CFBundleIdentifier</code> key of the <code>Info.plist</code> file every application bundle contains at its root.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload