macos 通过命令行 (mac) 添加启动项

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2564394/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 06:50:36  来源:igfitidea点击:

add a start up item via command line (mac)

macoscommand-linestartup

提问by nightfire

How can I add a start up item via command line on a mac? From googling, I know you have to edit ~/Library/Preferences/com.apple.loginitems.plistusing defaults write com.apple.loginitems [key] [value]but i'm not sure exactly which things to edit.

如何通过 Mac 上的命令行添加启动项?通过谷歌搜索,我知道您必须~/Library/Preferences/com.apple.loginitems.plist使用进行编辑, defaults write com.apple.loginitems [key] [value]但我不确定要编辑哪些内容。

采纳答案by Michael Aaron Safyan

On Mac OS X 10.6 Snow Leopard, it is even simpler than that:

在 Mac OS X 10.6 Snow Leopard 上,它甚至比这更简单:

sudo launchctl submit -l name_of_startup_item -- command [args]

See man launchctl. On earlier versions, it is recommended that you create a Launch Daemon PLISTfile and load/start it with launchctl rather than create a startup item... the startup items are the old school way.

请参阅man launchctl。在早期版本中,建议您创建Launch Daemon PLIST文件并使用 launchctl 加载/启动它,而不是创建启动项……启动项是老派方式。

回答by Andreas Xenos

defaults write loginwindow AutoLaunchedApplicationDictionary -array-add '{ "Path" = "/Applications/YourAppName.app"; "Hide" = 0; }'