Closed anarchy89 closed 1 year ago
Maybe this thread can help you
Maybe this thread can help you
So what's the syntax for launchd for battery charging off?
Maybe this thread can help you
So what's the syntax for launchd for battery charging off?
This should work, put this in ~/Library/LaunchAgents
as <name>.plist
:
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
<plist version=\"1.0\">
<dict>
<key>Label</key>
<string>com.battery_charging_off</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/battery</string>
<string>charging</string>
<string>off</string>
</array>
<key>RunAtLoad</key> <!— This run the above array at startup -->
<true/>
</dict>
</plist>
then save it and run in a terminal: sudo launchctl load ~/Library/LaunchAgents/<name>.plist
Maybe this thread can help you
So what's the syntax for launchd for battery charging off?
This should work, put this in
~/Library/LaunchAgents
as<name>.plist
:<?xml version=\"1.0\" encoding=\"UTF-8\"?> <!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"> <plist version=\"1.0\"> <dict> <key>Label</key> <string>com.battery_charging_off</string> <key>ProgramArguments</key> <array> <string>/usr/local/bin/battery</string> <string>charging</string> <string>off</string> </array> <key>RunAtLoad</key> <!— This run the above array at startup --> <true/> </dict> </plist>
then save it and run in a terminal:
sudo launchctl load ~/Library/LaunchAgents/<name>.plist
Thanks for this, I have another question, can I launch a pop up box everytime the operating system launches, that asks me whether I want to disable charging, if I click yes it will launch the script and no will do nothing. I tried using apple script and adding it as a startup item but I can't get it to work. Can this be used to do something similar ?
It should be possible!
You can create a shell script
that call Apple script with something like osascript -e "display dialog "
and on the output it runs or not battery charging off
!
After you create the script you have to change the ProgramArguments
in the .plist
file
K> It should be possible!
You can create a
shell script
that call Apple script with something likeosascript -e "display dialog "
and on the output it runs or notbattery charging off
!After you create the script you have to change the
ProgramArguments
in the.plist
file
So like,
osascript - "<<EOF
on run
tell application "Terminal"
do script "battery charging off"
end tell
end run
EOF
I save it as batteryoff.scpt
Then I the plist file I do
<string>/path/to/batteryoff.scpt</string>
?
Ehm, no! You can do something in that way, personally I prefer use shell script more and leave Apple script do only the dialog part.
Something like:
#!/usr/bin/env bash
output=$(osascript -e 'tell app "System Events" to display dialog “Set battery charging off?”')
if [[ $out == “button returned:OK” ]]; then
/usr/local/bin/battery charging off
fi
<name>
(the .sh
or other extensions part is not mandatory on Unix),chmod +x <name>
Now in the .plist
change to:
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
<plist version=\"1.0\">
<dict>
<key>Label</key>
<string>com.battery_charging_off</string>
<key>ProgramArguments</key>
<array>
<string>full_path_to_file_above(name)></string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
Probably there’s some fix to do, but this is the general idea!
When the system startup, it should prompt you the dialog and in case of “OK” pressed, it should run battery charging off
.
This is a good discussion, though outside the scope of the app. I'll close this issue for my own admin, but feel free to continue discussing!
Is there a way to run the command
battery charging off
on every startup?