Skip to main content
Glama
RunningApp.swift1.27 kB
import Foundation import XCTest import os struct RunningApp { static let springboardBundleId = "com.apple.springboard" private static let logger = Logger( subsystem: Bundle.main.bundleIdentifier!, category: String(describing: Self.self) ) private init() {} static func getForegroundAppId(_ appIds: [String]) -> String { if appIds.isEmpty { logger.info("Empty installed apps found") return "" } return appIds.first { appId in let app = XCUIApplication(bundleIdentifier: appId) return app.state == .runningForeground } ?? RunningApp.springboardBundleId } static func getForegroundApp() -> XCUIApplication? { let runningAppIds = XCUIApplication.activeAppsInfo().compactMap { $0["bundleId"] as? String } NSLog("Detected running apps: \(runningAppIds)") if runningAppIds.count == 1, let bundleId = runningAppIds.first { return XCUIApplication(bundleIdentifier: bundleId) } else { return runningAppIds .map { XCUIApplication(bundleIdentifier: $0) } .first { $0.state == .runningForeground } } } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mobile-dev-inc/Maestro'

If you have feedback or need assistance with the MCP directory API, please join our Discord server