本文介绍了如何知道特定的launchd.plist文件位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可能知道加载到launchctl命令中的.plist文件位置?

Is it possible to know the .plist file location which is loaded into the launchctl command?

标签名称以"launchctl list"列出,并且可以通过"launchctl list LABEL"查看其内容,但是找不到.plist文件位置.

The label name is listed with "launchctl list" and its contents can be viewed by "launchctl list LABEL", but I cannot find the .plist file location.

我知道它将位于/Library/LaunchAgent或〜/Library/LaunchAgent之类的位置,但是当launchctl命令列出了所有作业时,我不想在路径周围搜索.

I know it will be located in /Library/LaunchAgent or ~/Library/LaunchAgent or something,but I don't want to search around paths while all jobs is listed with the launchctl command.

推荐答案

此问题经常出现,不幸的是locatemdfind都没有显示系统中相应目录的结果.我在.bashrc中添加了以下函数,以便可以快速搜索launchctl在其中查找plist文件的目录.

This issue comes up a lot and unfortunately locate and mdfind both don't show results from the appropriate directories on my system. I put the following function in my .bashrc so I could quickly search the directories where launchctl looks for plist files.

launchctlFind () {
    LaunchctlPATHS=( \
        ~/Library/LaunchAgents \
        /Library/LaunchAgents \
        /Library/LaunchDaemons \
        /System/Library/LaunchAgents \
        /System/Library/LaunchDaemons \
    )

    for curPATH in "${LaunchctlPATHS[@]}"
    do
        grep -r "$curPATH" -e "$1"
    done
    return 0;
}

请注意,这只会在启动和登录时在launchctl查找文件的目录中进行检查.它可能找不到所有内容,因为作业可以由用户和/或其他进程手动加载.

Note that this only checks in the directories where launchctl looks for files at boot-up and login. It may not find everything because jobs can be manually loaded by the user and/or other processes.

更新:对于运行macOS 10.12.6或更高版本的用户,我建议使用下面的Joel Bruner解决方案.

UPDATE: For those running macOS 10.12.6 or higher I would recommend using Joel Bruner's solution below.

这篇关于如何知道特定的launchd.plist文件位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 04:12