Macos 如何使用shell脚本从登录项目中删除项目

Macos 如何使用shell脚本从登录项目中删除项目,macos,nsarray,shell,Macos,Nsarray,Shell,在Mac中, 我想使用Shell脚本从登录项中删除应用程序 我尝试了以下代码,但没有成功 defaults write loginwindow AutoLaunchedApplicationDictionary -array-remove path "/Applications/myApp.app" 但它给出了错误“意外参数-路径;保持默认值不变” 问候,, Dhanaraj-数组删除不存在…我通过以下方式解决了此问题: ln=`/usr/bin/defaults read /Libr

在Mac中, 我想使用Shell脚本从登录项中删除应用程序

我尝试了以下代码,但没有成功

   defaults write loginwindow  AutoLaunchedApplicationDictionary -array-remove path "/Applications/myApp.app"
但它给出了错误“意外参数-路径;保持默认值不变”

问候,,
Dhanaraj

-数组删除不存在…我通过以下方式解决了此问题:

ln=`/usr/bin/defaults read /Library/Preferences/loginwindow AutoLaunchedApplicationDictionary | grep "Path =" | sed -n '/myApp.app/='`
if [ "$ln" != "" ]
then
    echo $ln | /usr/bin/sort -nr | while read k
    do
        /usr/libexec/PlistBuddy -c "Delete :AutoLaunchedApplicationDictionary:$(($k-1)) dict" /Library/Preferences/loginwindow.plist
    done
fi