diff --git a/cmd/list-login-items-for-app.rb b/cmd/list-login-items-for-app.rb new file mode 100755 index 0000000000000..fcb77d7daf5cd --- /dev/null +++ b/cmd/list-login-items-for-app.rb @@ -0,0 +1,46 @@ +# typed: strict +# frozen_string_literal: true + +require "abstract_command" +require "open3" + +module Homebrew + module Cmd + class ListLoginItemsForAppCmd < AbstractCommand + cmd_args do + usage_banner <<~EOS + `list-login-items-for-app` + + Given an Application (app) bundle directory on disk, find all + login items associated with that app, which you can use in a + Cask uninstall stanza, eg + + uninstall login_item: "login item name" + + Note that you will likely need to have opened the app at least + once for any login items to be present. + + See CONTRIBUTING.md for more information. + EOS + + named_args :app_path, max: 1 + + hide_from_man_page! + end + + sig { override.returns(T.nilable(String)) } + def run + out, err, status = Open3.capture3( + "/usr/bin/osascript", "-e", + "tell application \"System Events\" to get the name of every login item " \ + "whose path contains \"#{File.basename(*args.named)}\"" + ) + unless status.success? + $stderr.puts err + exit status.exitstatus.to_i + end + puts out.gsub(", ", "\n") + end + end + end +end diff --git a/developer/bin/list_login_items_for_app b/developer/bin/list_login_items_for_app deleted file mode 100755 index 65296c4962f3e..0000000000000 --- a/developer/bin/list_login_items_for_app +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true - -# Standalone scripts are fine to use global variables -# rubocop:disable Style/GlobalVars - -# -# list_login_items_for_app -# - -### -### dependencies -### - -require "open3" - -### -### methods -### - -def usage - <<~EOS - Usage: list_login_items_for_app - - Given an Application (app) bundle directory on disk, find all - login items associated with that app, which you can use in a - Cask uninstall stanza, eg - - uninstall login_item: 'login item name' - - Note that you will likely need to have opened the app at least - once for any login items to be present. - - See CONTRIBUTING.md for more information. - - EOS -end - -def process_args - if /^-+h(?:elp)?$/.match?(ARGV.first) - puts usage - exit 0 - elsif ARGV.length == 1 - $app_path = ARGV.first - else - puts usage - exit 1 - end -end - -def list_login_items_for_app(app_path) - out, err, status = Open3.capture3( - "/usr/bin/osascript", "-e", - "tell application \"System Events\" to get the name of every login item " \ - "whose path contains \"#{File.basename(app_path)}\"" - ) - if status.exitstatus.positive? - $stderr.puts err - exit status.exitstatus - end - puts out.gsub(", ", "\n") -end - -### -### main -### - -process_args -list_login_items_for_app $app_path - -# rubocop:enable Style/GlobalVars