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
63 changes: 63 additions & 0 deletions cmd/list-installed-launchjob-ids.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# typed: strict
# frozen_string_literal: true

require "abstract_command"
require "open3"

module Homebrew
module Cmd
class ListInstalledLaunchjobIdsCmd < AbstractCommand
cmd_args do
description <<~EOS
List all installed launchjob IDs, which may be useful
in a Cask uninstall stanza, e.g.:

uninstall launchctl: "job.id.goes.here"

Launchctl jobs attributed to Apple will be omitted.

If a launchctl job is currently loaded, and visible to the current
user, it will be followed by a plus symbol '(+)' in the output.
This can be verified via the command:

/bin/launchctl list 'job.id.goes.here'

See CONTRIBUTING.md and 'man launchctl' for more information.
EOS

named_args :none

hide_from_man_page!
end

sig { override.returns(T.nilable(String)) }
def run
loaded = list_loaded_launchjob_ids
pattern = "{#{Dir.home},}/Library/Launch{Agents,Daemons}/**.plist"
puts Pathname
.glob(pattern)
.filter(&:readable?)
.filter_map { method(:read_label).call(it) }
.reject { it.start_with? "com.apple." }
.uniq.sort
.map { loaded.include?(it) ? "#{it} (+)" : it }
end

sig { params(plist: Pathname).returns(T.nilable(String)) }
def read_label(plist)
xml = plist.read
if xml.start_with? "bplist"
xml, _, status = Open3.capture3("/usr/bin/plutil -convert xml1 -o - '#{plist}'")
return unless status.success?
end
Plist.parse_xml(xml, marshal: false)["Label"]
end

sig { returns(T::Array[T.nilable(String)]) }
def list_loaded_launchjob_ids
loaded, = Open3.capture3("/bin/launchctl list")
loaded.lines.map { it.split(/\s+/).last }
end
end
end
end
90 changes: 0 additions & 90 deletions developer/bin/list_installed_launchjob_ids

This file was deleted.

Loading