macOS-launchctl启动项管理工具

启动项管理工具 launchctl

  • 打印当前用户禁用的启动项
1
launchctl print-disabled "user/$(id -u)"
  • 启动一个启动项
1
launchctl kickstart -p "user/$(id -u)"/org.whatpulse.ChmodBPF

其它: service-name service-target 区别
https://apple.stackexchange.com/questions/166397/what-is-the-difference-between-a-service-name-and-a-service-target

概念

启动文件位置:
Behind the UNIX curtain: Instead of opening apps directly, launchd loads specially formatted .plist documents (XML preference files) that specify what should launch and under what circumstances. Sometimes these launch items run constantly in the background, sometimes they run at scheduled intervals, and sometimes they run as needed—for example, in response to an event such as a change in a certain file or folder—and then quit.

The .plist files that launchd uses can occupy any of five folders, and their location determines when the items load and with what privileges:

  • Items in /Library/LaunchDaemons and /System/Library/LaunchDaemons load when your Mac starts up, and run as the root user.

  • Items in /Library/LaunchAgents and /System/Library/LaunchAgents load when any user logs in, and run as that user.

  • Items in ~/Library/LaunchAgents load only when that particular user logs in, and run as that user.

  • lists

    /Library/LaunchDaemons 启动时使用root用户运行
    /System/Library/LaunchDaemons 启动时使用root用户运行
    /Library/LaunchAgents 登录时使用登录用户运行
    /System/Library/LaunchAgents 登录时使用登录用户运行
    /Library/LaunchAgents 登录时使用指定的用户运行

更多参考:《终端使用手册》 - 在 Mac 上的“终端”中使用 launchd 管理脚本


macOS-launchctl启动项管理工具
https://dnacore.github.io/post/cb18f32c-c16f-4e49-9202-8bcdd4edd848.html
作者
DNACore
发布于
2019年5月25日
更新于
2024年1月10日
许可协议