Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions cmd/list-running-app-ids.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# typed: strict
# frozen_string_literal: true

require "abstract_command"
require "open3"

module Homebrew
module Cmd
class ListRunningAppIdsCmd < AbstractCommand
cmd_args do
usage_banner <<~EOS
`list-running-app-ids` [<bundle-id>]

Print a list of currently running Applications and associated
Bundle IDs, which may be useful in a Cask uninstall stanza, eg

uninstall quit: 'bundle.id.goes.here'

Applications attributed to Apple are excluded from the output.

With optional <bundle-id>, silently test if a given app
is running, setting a failing exit code if not.

See CONTRIBUTING.md for more information.
EOS

named_args :bundle_id, max: 1

hide_from_man_page!
end

sig { override.void }
def run
app_names, bundle_ids = load_apps
test_bundle_id = args.named.first

if test_bundle_id
Homebrew.failed = true unless bundle_ids.include?(test_bundle_id)
else
report_apps(app_names, bundle_ids)
Comment on lines +32 to +40
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When a is provided, the command sets Homebrew.failed = true but does not explicitly return/exit non-zero. Within this repo’s other tap commands (e.g. cmd/find-appcast.rb), failure is indicated by the method’s boolean return value rather than setting a global flag. Please ensure brew list-running-app-ids <bundle-id> reliably exits with a non-zero status when the bundle id is not running (so callers like developer/bin/list_ids_in_app can detect it).

Suggested change
sig { override.void }
def run
app_names, bundle_ids = load_apps
test_bundle_id = args.named.first
if test_bundle_id
Homebrew.failed = true unless bundle_ids.include?(test_bundle_id)
else
report_apps(app_names, bundle_ids)
sig { override.returns(T::Boolean) }
def run
app_names, bundle_ids = load_apps
test_bundle_id = args.named.first
if test_bundle_id
running = bundle_ids.include?(test_bundle_id)
Homebrew.failed = true unless running
running
else
report_apps(app_names, bundle_ids)
true

Copilot uses AI. Check for mistakes.
end
end

private

sig { returns([T::Array[String], T::Array[String]]) }
def load_apps
out, err, status =
Open3.capture3("/usr/bin/osascript", "-e",
'tell application "System Events" to get ' \
"(name, bundle identifier, unix id) of every process")
odie(err) if status.exitstatus != 0

parts = out.split(", ")
one_third = parts.length / 3
app_names = parts.shift(one_third)
bundle_ids = parts.shift(one_third)
[app_names, bundle_ids]
end

sig { params(bundle_id: String).returns(T::Boolean) }
def excluded_bundle_id?(bundle_id)
bundle_id.start_with?("com.apple.")
end

sig { params(app_name: String).returns(T::Boolean) }
def excluded_app_name?(app_name)
app_name == "osascript"
end

sig { params(app_names: T::Array[String], bundle_ids: T::Array[String]).void }
def report_apps(app_names, bundle_ids)
col_width = Tty.width / 2
running = Set.new

app_names.zip(bundle_ids).each do |app_name, bundle_id|
next if bundle_id.nil? || app_name.nil?
next if excluded_bundle_id?(bundle_id)
next if excluded_app_name?(app_name)

display_id = bundle_id.gsub(/^(missing value)$/, '<\1>')
running.add "#{display_id.ljust(col_width)}\t#{app_name}"
end

puts "#{"bundle_id".ljust(col_width)}\tapp_name"
puts "-" * Tty.width
puts running.to_a.sort.join("\n")
end
end
end
end
4 changes: 2 additions & 2 deletions developer/bin/list_ids_in_app
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ clean_sources () {
mark_up_sources () {
/usr/bin/perl -pe 's{\n}{\000}sg' | \
"$xargs" -0 -I{} -n1 /bin/bash -c \
"printf '{}'; $scriptdir/list_running_app_ids -t '{}' >/dev/null 2>&1 && printf ' (+)'; printf "\\\\n""
"printf '{}'; brew list-running-app-ids '{}' >/dev/null 2>&1 && printf ' (+)'; printf "\\\\n""
}

###
Expand Down Expand Up @@ -151,7 +151,7 @@ are excluded from the output.
If a given app is currently running, it will be followed by a plus
symbol '(+)' in the output. This can be verified via the command

list_running_app_ids | grep 'app.id.goes.here'
brew list-running-app-ids | grep 'app.id.goes.here'

See CONTRIBUTING.md for more information.

Expand Down
125 changes: 0 additions & 125 deletions developer/bin/list_running_app_ids

This file was deleted.

Loading