Open dingwen07 opened 11 months ago
@zackelia it should work something like this:
class Bclm < Formula
desc "macOS command-line utility to limit max battery charge"
homepage "https://github.com/zackelia/bclm”
version "0.1.0"
url "https://github.com/zackelia/bclm/releases/download/v#{version}/bclm.zip"
sha256 "3f0148e107846e83c7b85282d98ce8611609084920ff0757ab4a017837d54a97"
license "https://github.com/zackelia/bclm/blob/main/LICENSE"
depends_on macos: :mavericks
def install
bin.install "bclm"
end
end
service do
run macos: [opt_bin/“bclm”, “write”, “#{value_passed_from_shell}" ]
keep_alive true
log_path var/“log/bclm/stdout.log"
error_log_path var/“log/bclm/stderr.log"
end
end
The only thing that it’s a little tricky, is that (especially for Intel Macs), this brew formula is copied on install into
{/opt/homebrew, /usr/local}/Library/Taps/zackelia/homebrew-formulae/Formula
, so the write value to be passed is already copied into /Library/LaunchDaemons
by brew.
Due to this, have a specific value for the battery percentage could be tricky to handle, since with brew it’s not flexible as populating the plist via Swift.
Homebrew Services is a way to manage background services (using
launchctl
) for homebrew formulas. Using it to managepersist
feature might be a good choice.