Mac自启动程序管理
添加或移除启动程序,可以直接在偏好设置里面修改,首先我们需要进入系统偏好设置
然后进入用户与群组
切换至登录项,在这里我们可以添加或移除登录项
但是有时候我们发现有些自启动的软件在这里面是找不到的,这个时候我们可以通过终端程序查找。
macOS系统的启动项会以 .plist
的文件存在于以下目录中:
/Library/LaunchDaemons
:系统启动时运行,用户不登录也会运行。/Library/LaunchAgents
:用户登录后运行。~/Library/LaunchAgents
:用户自定义的用户启动项/System/Library/LaunchDaemons
:系统自带的启动项/System/Library/LaunchAgents
:系统自带的启动项
每个 .plist 文件中,有 3 个属性控制着是否会开机自动启动。
KeepAlive
:决定程序是否需要一直运行,如果是false
则需要时才启动。默认false
RunAtLoad
:开机时是否运行。默认false
。SuccessfulExit
:此项为true
时,程序正常退出时重启(即退出码为 0);为false
时,程序非正常退出时重启。此项设置时会隐含默认RunAtLoad = true
,因为程序需要至少运行一次才能获得退出状态。
所以其实针对这三项,不同的值有不同的表现:
- 如果
KeepAlive = false
:- 当
RunAtLoad = false
时:程序只有在有需要的时候运行。 - 当
RunAtLoad = true
时:程序在启动时会运行一次,然后等待在有需要的时候运行。 - 当
SuccessfulExit = true / false
时:不论RunAtLoad
值是什么,都会在启动时运行一次。其后根据SuccessfulExit
值来决定是否重启。
- 当
- 如果
KeepAlive = true
:不论RunAtLoad/SuccessfulExit
值是什么,都会启动时运行且一直保持运行状态。
所以如果我们不希望开机自动运行,则需要:
- 找到对应程序的
.plist
文件 - 删除
SuccessfulExit
属性。 - 将
RunAtLoad / KeepAlive
均设为<false/>
另外附上JAVA扫描开机自启动plist
文件的代码供大家参考
1、MAVEN配置
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.jianggujin</groupId><artifactId>MacAutoRunScan</artifactId><version>1.0.0</version><name>MacAutoRunScan</name><description>Mac自启动扫描</description><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><!-- build --><maven-compiler-plugin.version>3.1</maven-compiler-plugin.version><maven-surefire-plugin.version>2.18.1</maven-surefire-plugin.version><java.version>1.8</java.version><maven.compiler.source>${java.version}</maven.compiler.source><maven.compiler.target>${java.version}</maven.compiler.target><junit.version>4.12</junit.version></properties><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>${junit.version}</version><scope>test</scope></dependency><dependency><groupId>com.googlecode.plist</groupId><artifactId>dd-plist</artifactId><version>1.20</version></dependency></dependencies><build><resources><resource><directory>src/main/java</directory><includes><include>**/*.xml</include></includes><filtering>true</filtering></resource><resource><directory>src/main/resources</directory><filtering>true</filtering></resource></resources><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId><version>${maven-surefire-plugin.version}</version></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>${maven-compiler-plugin.version}</version></plugin></plugins></build>
</project>
2、java代码
package com.jianggujin.macautorunscan;/** 启动类型*/
public enum LaunchType {SystemLaunchDaemons("/System/Library/LaunchDaemons"), SystemLaunchAgents("/System/Library/LaunchAgents"), LaunchDaemons("/Library/LaunchDaemons"), LaunchAgents("/Library/LaunchAgents"), UserLaunchAgents("~/Library/LaunchAgents");private String path;private LaunchType(String path) {this.path = path;}public String getPath() {return this.path;}
}
package com.jianggujin.macautorunscan;import java.io.File;import com.dd.plist.NSDictionary;
import com.dd.plist.NSNumber;
import com.dd.plist.NSObject;
import com.dd.plist.PropertyListParser;public class LaunchPList {private final File plist;private final LaunchType launchType;private NSDictionary dictionary = null;private Boolean keepAlive;private Boolean runAtLoad;private Boolean successfulExit;public LaunchPList(File plist, LaunchType launchType) {this.plist = plist;this.launchType = launchType;}public File getPlist() {return this.plist;}public LaunchType getLaunchType() {return launchType;}public Boolean getKeepAlive() {ensureParse();return keepAlive;}public Boolean getRunAtLoad() {ensureParse();return runAtLoad;}public Boolean getSuccessfulExit() {ensureParse();return successfulExit;}public String getXMLPropertyList() {ensureParse();return dictionary.toXMLPropertyList();}private Boolean getBooleanValue(String key) {NSObject value = null;if (dictionary.containsKey(key)) {value = dictionary.objectForKey(key);if (value instanceof NSNumber) {NSNumber number = (NSNumber) value;return Boolean.valueOf(number.boolValue());}}return null;}public boolean isAutoRun() {ensureParse();return keepAlive == Boolean.TRUE || runAtLoad == Boolean.TRUE || successfulExit != null;}private synchronized void ensureParse() {if (dictionary == null) {try {this.dictionary = (NSDictionary) PropertyListParser.parse(plist);this.keepAlive = getBooleanValue("KeepAlive");this.runAtLoad = getBooleanValue("RunAtLoad");this.successfulExit = getBooleanValue("SuccessfulExit");} catch (Exception e) {e.printStackTrace();dictionary = null;keepAlive = null;runAtLoad = null;successfulExit = null;}}}@Overridepublic String toString() {ensureParse();return "LaunchPList [plist=" + plist.getAbsolutePath() + ", launchType=" + launchType + ", keepAlive=" + keepAlive+ ", runAtLoad=" + runAtLoad + ", successfulExit=" + successfulExit + "]";}
}
package com.jianggujin.macautorunscan;import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;public class LaunchScan {public static List<LaunchPList> scan(String name, LaunchType... launchTypes) {List<LaunchPList> launchPLists = new ArrayList<>();for (LaunchType launchType : launchTypes) {File root = new File(launchType.getPath());if (root.exists()) {File[] plists = root.listFiles(new FileNameFilter(name));if (plists != null) {for (File plist : plists) {launchPLists.add(new LaunchPList(plist, launchType));}}}}return launchPLists;}static class FileNameFilter implements FilenameFilter {private Pattern pattern = null;;public FileNameFilter(String name) {if (name != null) {pattern = Pattern.compile(name);}}@Overridepublic boolean accept(File dir, String name) {if (!name.endsWith(".plist")) {return false;}if (pattern != null) {return pattern.matcher(name).matches();}return true;}}
}
假如我们要扫描teamviewer
的plist文件,我们可以这样写:
import java.util.List;import org.junit.Test;import com.jianggujin.macautorunscan.LaunchPList;
import com.jianggujin.macautorunscan.LaunchScan;
import com.jianggujin.macautorunscan.LaunchType;public class ScanTest {@Testpublic void test() {List<LaunchPList> launchPLists = LaunchScan.scan(".*teamviewer.*", LaunchType.SystemLaunchDaemons,LaunchType.SystemLaunchAgents, LaunchType.LaunchDaemons, LaunchType.LaunchAgents,LaunchType.UserLaunchAgents);launchPLists.forEach(item -> {if (item.isAutoRun())System.err.println(item);});}
}
扫描参考结果如下:
LaunchPList [plist=/Library/LaunchDaemons/com.teamviewer.teamviewer_service.plist, launchType=LaunchDaemons, keepAlive=true, runAtLoad=true, successfulExit=null]
LaunchPList [plist=/Library/LaunchAgents/com.teamviewer.teamviewer.plist, launchType=LaunchAgents, keepAlive=true, runAtLoad=true, successfulExit=null]
LaunchPList [plist=/Library/LaunchAgents/com.teamviewer.teamviewer_desktop.plist, launchType=LaunchAgents, keepAlive=true, runAtLoad=true, successfulExit=null]
Mac自启动程序管理相关推荐
- Windows下自启动程序管理
一.自启动程序在注册表中的查找 通过msconfig调出系统配置对话框,在启动项中查找当前开机自启动的程序,以及其在注册表中的位置 http://blog.163.com/lts1977@126/bl ...
- Ubuntu管理开机自启动程序
点击左侧的图标,在搜索栏上输入gnome-session,即可看到 "启动应用程序"的图标, 如下图: 在此管理开机自启动程序
- 鸟哥的Linux私房菜(基础篇)- 第十七章、程序管理与 SELinux 初探
第十七章.程序管理与 SELinux初探 最近升级日期:2009/09/11 一个程序被加载到内存当中运行,那么在内存内的那个数据就被称为程序(process).程序是操作系统上非常重要的概念,所有系 ...
- 苹果电脑怎么打开计算机管理,mac开机启动管理怎么设置_mac如何设置开机启动管理-win7之家...
在使用mac电脑的过程中,有些用户由于安装软件时忘记了设置程序启动,导致每次在打开mac电脑时总会伴随着一些软件的自动开启,严重影响到电脑的启动速度,这时我们就可以对mac开机启动管理进行重新设置,那 ...
- AnyTrans for iOS for mac(ios数据传输管理工具)
AnyTrans 是一款专业的ios管理工具,以聪明的方式管理.传输.备份.导出.导入.删除.修改.上传.管理所有的iOS数据和文件,在一个便利的地方完全管理你的iPhone,iPad,iPod,甚至 ...
- Mountain Duck for Mac(云存储空间管理软件) v2.6.7永久破解版
如何将您的云空间进行本地化管理?那就全靠Mountain Duck这款好用的云存储空间管理软件了!Mountain Duck Mac与我们熟悉的Cyberduck是一对孪生兄弟.这只山鸭擅长的是将你的 ...
- 手机程序管理常见不规范的软件名称列表
手机程序管理常见不规范的软件名称列表 2011年10月11日 所谓不规范的软件名称,即以图标的形式删除软件后仍有残留相关软件显示在列表中.显示在程序管理的名称和原程序的中文名/英文名相差甚远,甚至是安 ...
- Win10系统如何关闭开机自启动程序,看这里就够了,怎样关闭Windows10电脑自启动软件
现如今我们大家不论是生活中还是工作中运用电脑都是甚为广泛,对于电脑的操作,有人会把一些软件设置为开机自启动,如果当我们不需要自启动的时候怎样关闭自启动程序呢?不能自启动软件开一次你手动关一次吧,这样太 ...
- 我好像很久没安利软件给大家啦,今天给大家种草一款OmniFocus for Mac(GTD时间管理工具)标准版
OmniFocus for Mac版是设计用来快速捕捉你的想法,并允许您存储,管理和处理可操作的待办事项.完美的GTD系统,在任何任务上都足够灵活的管理风格,OmniFocus 3 mac中给你一个始 ...
- 关闭计算机启动程序,电脑开机时自启动程序烦人,教你用系统自带程序关闭它!...
电脑每次开启的时候会有一些应用程序也跟着自动启动,占用着电脑系统资源.有时候我们并不需要这些程序开启,那么我们如何关闭这些的开机自动启动项呢?这时,有装一些第三方安全管理软件的可以利用它们来管理,但这 ...
最新文章
- 8则实用的Linux Shell命令
- 线程中的yield()
- tkinter笔记:scale 尺度 (莫烦python笔记)
- 小米路由器青春版装linux,比较费心的折腾 篇二:小米路由器青春版折腾负载均衡...
- 使用touch更新文件的时间
- 前端学习(3239):react生命周期setstate流程
- Java1.7之后Arrays.sort对数组排序DualPivotQuicksort.sort
- java中怎么声明常量_如何在Java中声明一个常量
- matlab处理最优化问题,matlab求最优化问题
- 拼多多公布新iPhone SE补贴后价格:2899元起;BOSS直聘回应“App崩了”;Chrome 新测试版发布|极客头条...
- logstash增量读取mysql中的数据到es中
- 学python语言有前途吗-在成都学Python有发展前景吗?
- 【机器学习系列】MCMC第二讲:Markov Chain Monte Carlo基本概念和核心思想
- Proteus8.10软件安装教程
- excel 制作二维码
- 在前端如何玩转 Word 文档
- 浏览器主页被修改的解决方案
- Android产品研发(十六)--开发者选项
- Microsoft Visual Studio - 代码格式化设置项
- 图灵学院专用-- 00JVM参数手册
热门文章
- 一文带你认识微内核,华为“鸿蒙”操作系统微内核到底是什么?
- vmwareshanch删除快照以及删除快照时卡住的解决办法
- mac快捷键:轻松提升mac使用效率
- 我的世界java版怎么加整合包_我的世界java如何下载安装optifine和forge及整合包和常见问题[纯小白教程]...
- 移动apn接入点哪个快_千兆交换机和快速以太网交换机哪个更好呢?
- Angular 2 升级到 Angular 5
- Mip-NeRF学习
- 国内主要的PDM产品关于浏览圈阅模块的总结(2006)
- SAP开发入门-ABAP
- 终极版Python打包exe文件,并修改图标,这将是你见过最详细的教程~