Macos 通过命令行在High Sierra上使用launchctl加载.plist 概述:

Macos 通过命令行在High Sierra上使用launchctl加载.plist 概述:,macos,plist,macos-high-sierra,launchctl,Macos,Plist,Macos High Sierra,Launchctl,我正在尝试为MacMini的套件在教学套件中运行执行以下操作 干净安装后(使用Apple remote desktop和bash脚本) 安装一些应用程序(Chrome、Logic、Imovie) 创建一个用户(本例中的u:p student/student) 将家长控制添加到此用户,并限制他们可以使用的应用 修改Dock(通过plist文件)以仅显示我们想要的应用程序,并在每次启动时运行此操作(以防止学生为下一个用户弄乱它) 我90%的时间都在工作,但我完全无法让我的plist工作并加载 它在我

我正在尝试为MacMini的套件在教学套件中运行执行以下操作

干净安装后(使用Apple remote desktop和bash脚本)
  • 安装一些应用程序(Chrome、Logic、Imovie)
  • 创建一个用户(本例中的u:p student/student)
  • 将家长控制添加到此用户,并限制他们可以使用的应用
  • 修改Dock(通过plist文件)以仅显示我们想要的应用程序,并在每次启动时运行此操作(以防止学生为下一个用户弄乱它)
  • 我90%的时间都在工作,但我完全无法让我的plist工作并加载

    它在我的电脑(也是10.13)上工作,加载良好,它可以作为管理员在同一台mac上加载。 试图以用户身份加载它是不起作用的

    当前进程
  • 运行下面的Bash脚本:

    #! /bin/bash
    
    # Supercedes the above make user , this CANNOT be run as root , so run as the administrator user we added at creation.
    sysadminctl -addUser student -fullName "Bamm Student" -password student -hint student 
    createhomedir -c /Users/student
    
    # Import the parental controls plist
    dscl . -mcximport /Users/student /tmp/parental_controls.plist
    
    # Dock script needs to be copied to the correct location first
    
    # Set the permissions on the dock script
    chmod +x /usr/local/dock.sh 
    chown student:staff /usr/local/dock.sh
    
  • 这部分都可以工作,我得到一个用户,我得到home dir,我把dock脚本复制到
    /usr/local
    (当用户从命令行运行时,它也可以工作)

  • 我将plist文件复制到位置
    /Users/student/LaunchAgents/
  • 确保其所有者为学生:员工
  • 确保它是644权限
  • dock脚本是可执行的,由学生用户拥有,可以作为学生用户从命令行运行(通过ssh会话)
  • 这是行不通的(我试过很多方法)

    给出
    /Users/temp/Library/LaunchAgents/com.mitsuite.login.plist:不允许操作

    我也试过了

    launchctl bootstrap gui/502 /Users/student/Libray/launchAgent/com.mitsuite.login.plist
    
    give
    找不到的域

    launchctl bootstrap user/502 /Users/student/Libray/launchAgent/com.mitsuite.login.plist
    
    system.log
    中,这些错误给了我各种各样的错误,主要是这样的:

    Aug 10 15:12:59 MIT-1 com.apple.xpc.launchd[1] (com.apple.xpc.launchd.user.domain.501.100008.Aqua): Caller not allowed to perform action: launchctl.671, action = service bootstrap, code = 1: Operation not permitted, uid = 502, euid = 502, gid = 20, egid = 20, asid = 649
    
    <?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>local.job</string>
            <key>Program</key>
            <string>/usr/local/dock.sh</string>
            <key>RunAtLoad</key>
            <true/>
        </dict>
    </plist>
    
    我曾经尝试过创建一个标准用户,但没有添加任何parentaly控件(通过管理面板,没有脚本编写的乐趣),也遇到了同样的问题

    我的Plist如下所示:

    Aug 10 15:12:59 MIT-1 com.apple.xpc.launchd[1] (com.apple.xpc.launchd.user.domain.501.100008.Aqua): Caller not allowed to perform action: launchctl.671, action = service bootstrap, code = 1: Operation not permitted, uid = 502, euid = 502, gid = 20, egid = 20, asid = 649
    
    <?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>local.job</string>
            <key>Program</key>
            <string>/usr/local/dock.sh</string>
            <key>RunAtLoad</key>
            <true/>
        </dict>
    </plist>
    
    
    标签
    本地工作
    节目
    /usr/local/dock.sh
    运行负荷
    
    更新: 作为一个测试,我在同一台计算机上创建了一个管理员用户,并运行了这个,加载plist并在引导时运行都很好

    如何让标准用户通过命令行安装plist

    更新2: 从另一个Stackoverflow问题中,我将用户名添加到.plist文件中,然后将其放置在/Library/LaunchDaemons中,当root用户运行launchctl load/Library/LaunchDaemons/com.mitquit.login.plist时,这一切都会起作用


    然而,这似乎有悖常理(除非是因为标准用户无法安装应用程序而故意这么做?

    我会尝试做两件事:

    • 标签下
      字段中的值更改为
      com.mitsuite.login
      而不是
      local.job
    • 或添加到.plist(至少前两行):

      用户名
      /*用户的名称*/
      组名
      /*组名称*/
      初始组
      

    问题不在于.plist文件(它适用于管理员用户),而在于标准用户无法针对自己的用户运行launchctl