Module: OS::Mac::FFI::AppKit Private

Extended by:
NativeLibrary
Defined in:
os/mac/ffi/app_kit.rb

Overview

This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.

AppKit.framework wrapper

Class Method Summary collapse

Class Method Details

.bundle_identifier_for_pid(pid) ⇒ String?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

AppKit/NSRunningApplication.h:

+ (NSRunningApplication *)runningApplicationWithProcessIdentifier:(pid_t)pid;
@property(readonly, copy) NSString *bundleIdentifier;

Returns nil if the process is not an application known to Launch Services.

Parameters:

Returns:



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'os/mac/ffi/app_kit.rb', line 22

def self.bundle_identifier_for_pid(pid)
  # Ensure the framework is loaded so the Objective-C runtime knows the class.
  handle

  application = ObjectiveC.message_send(
    ObjectiveC.class_get("NSRunningApplication"),
    "runningApplicationWithProcessIdentifier:",
    [Fiddle::TYPE_INT],
    Fiddle::TYPE_VOIDP,
    pid,
  )
  return if application.null?

  bundle_identifier = ObjectiveC.message_send(application, "bundleIdentifier", [], Fiddle::TYPE_VOIDP)
  return if bundle_identifier.null?

  ObjectiveC.message_send(bundle_identifier, "UTF8String", [], Fiddle::TYPE_VOIDP).to_s
end