code: def getAppRefByBundleId(cls, bundleId):
          
          ra = AppKit.NSRunningApplication
          # return value (apps) is always an array. if there is a match it will
          # have an item, otherwise it won't.
          apps = ra.runningApplicationsWithBundleIdentifier_(bundleId)
          if len(apps) == 0:
              raise ValueError(('Specified bundle ID not found in '
                              'running apps: %s' % bundleId))
          pid = apps[0].processIdentifier()
          return cls.getAppRefByPid(pid)
docs: Get the top level element for the application with the specified
          bundle ID, such as com.vmware.fusion.