Command: List Devices
Relevant source files
The following files were used as context for generating this wiki page:
The devices command enumerates all available media capture components on the system, including displays, on-screen windows, and audio hardware. It provides users with the identifiers and metadata required to target specific sources for recording or monitoring.
This command serves as a discovery utility within the spike toolset. It allows you to identify Display IDs for Command: Record System and Window IDs or titles for Command: Record Window.
Sources: Sources/Spike/main.swift:18-19, Sources/Spike/DevicesCmd.swift:1-41
Device Enumeration Flow
The command executes three distinct discovery processes to gather information from different macOS frameworks. It prints categorized results to the standard output.
The diagram shows the sequential discovery of screen and audio resources across different system frameworks.
Sources: Sources/Spike/DevicesCmd.swift:7-40
Display and Window Discovery
The tool uses the ScreenCaptureKit (SCK) framework to retrieve shareable content. It filters the window list to show only windows currently visible on the screen.
Captured Metadata
| Component | Data Fields | Source |
|---|---|---|
| Displays | Index, Resolution (Width x Height), DisplayID | SCShareableContent.displays |
| Windows | WindowID, Owner Bundle ID, Title, Resolution | SCShareableContent.windows |
Sources: Sources/Spike/DevicesCmd.swift:7-21, Sources/Spike/Doctor.swift:42-47
Audio Device Analysis
Audio devices are identified using two methods: the low-level CoreAudio Hardware Abstraction Layer (HAL) and the high-level AVFoundation framework.
CoreAudio HAL Integration
The AudioHAL utility queries the system for AudioObjectID instances. It determines device capabilities by checking the number of input and output channels.
- Default Output: Marked with
←既定出力. - BlackHole: Identified by the presence of "BlackHole" in the device name, marked with
←BlackHole. - kilde Monitor: Identified by a specific UID for aggregate devices created by the tool.
Sources: Sources/Spike/AudioDevices.swift:9-40, Sources/Spike/MonitorCmd.swift:33-40, Sources/Spike/DevicesCmd.swift:24-33
AVCapture Integration
The command uses AVCaptureDevice.DiscoverySession to list audio devices specifically compatible with AVFoundation capture sessions. This list typically includes built-in and external microphones.
Sources: Sources/Spike/DevicesCmd.swift:36-40, Sources/Spike/Doctor.swift:58-64
Technical Implementation
The command relies on the awaitSync utility to handle asynchronous framework calls within the synchronous CLI execution context.
// Example of SCK retrieval in DevicesCmd.swift
let content = try awaitSync {
try await SCShareableContent.current
}
Sources: Sources/Spike/DevicesCmd.swift:9-11, Sources/Spike/Util.swift:20-33
Audio Device Properties
The system identifies audio hardware through specific property addresses.
| Property Selector | Description |
|---|---|
kAudioHardwarePropertyDevices | Retrieves IDs for all audio hardware |
kAudioDevicePropertyDeviceNameCFString | Retrieves the human-readable device name |
kAudioDevicePropertyDeviceUID | Retrieves the unique persistent identifier |
kAudioDevicePropertyStreamConfiguration | Used to count input and output channels |
Sources: Sources/Spike/AudioDevices.swift:42-105
Usage Summary
To list all devices, run:
spike devices
If the command fails to list displays or windows, ensure permissions are granted by running spike doctor.
Sources: Sources/Spike/main.swift:24-25, Sources/Spike/Doctor.swift:1-15