macOS LaunchDaemons自定义plist

This article is categorized as "Garbage" . It should NEVER be appeared in your search engine's results.


这篇笔记提到过pmset会被macOS的更新重置:🔗 [These Settings Might be Reset After a macOS Update - Truxton's blog] https://truxton2blog.com/these-settings-might-be-reset-after-a-macos-update/

所以我选择往 /Library/LaunchDaemons/ 里面写自定义的plist文件,每次启动macOS的时候都会确保pmset被正确设置。

遇到的问题1:明明看起来plist文件没问题,但quicklook就是不显示文件内容

原因:实际上那个plist文件就是有语法错误。把语法错误修正以后quicklook就会正常显示。

遇到的问题2:修复了语法问题,但重启macbook以后没有任何变化(plist不执行)

原因:权限问题。我用Finder复制粘贴了其他程序的plist,但其他程序的plist实际上是root权限的644(文件所有者是root),而我复制过来的文件虽然需要root密码,但复制过来的文件所有者是普通用户。如果用 sudo vim /Library/LaunchDaemons/xxxxx.plist 就不会有这个问题。

好不容易调通了(重启了好几次,硬试出来的),结果发现我踩过的坑都在这篇博客里提到过:🔗 [控制macOS的开机启动项] https://flxdu.cn/2022/07/08/控制macOS的开机启动项/

上面这篇博客里还有其他常见命令,这样就不需要反复重启来调试了:

https://flxdu.cn/2022/07/08/控制macOS的开机启动项/

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>localhost.pmset1.plist</string>
    <key>ProgramArguments</key>
    <array>
        <string>pmset</string>
        <string>-a</string>
        <string>hibernatemode</string>
        <string>0</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</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>localhost.pmset2.plist</string>
    <key>ProgramArguments</key>
    <array>
        <string>pmset</string>
        <string>-b</string>
        <string>powernap</string>
        <string>0</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

Leave a Comment Anonymous comment is allowed / 允许匿名评论