在Mac上可以像在Linux上一样,使用crontab来定时运行脚本,但苹果并不推荐这个方法。苹果推荐使用Launchctl来完成定时任务。

首先,我们先写一个可执行的脚本,列子为php脚本,名字为test.php.

其次,要到相对应的目录下面建立plist文件。

一共有5个文件夹,差别在于,Agents文件夹下的plist是需要用户登录后,才会加载的,而Daemons文件夹下得plist是只要开机,可以不用登录就会被加载

然后,我们编写plist文件

<?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>Disabled</key>
<false/>
<key>KeepAlive</key>
<false/>
<key>Label</key>
<string>com.ryan.test</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/php</string>
<string>/Users/Ryan/Zend/workspaces/DefaultWorkspace/test/test.php</string>
</array>
<key>RunAtLoad</key>
<false/>
<key>StandardErrorPath</key>
<string>/Users/Ryan/Documents/test_log/stderr</string>
<key>StandardOutPath</key>
<string>/Users/Ryan/Documents/test_log/stdout</string>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer></integer>
<key>Minute</key>
<integer></integer>
</dict>
</dict>
</plist>

最后,我们需要load写好的plist文件

launchctl load -w /Library/Daemons/com.ryan.test.plist    // 加载

launchctl unload -w /Library/Daemons/com.ryan.test.plist    // 卸载

参考文档地址:http://launchd.info

工具地址:http://www.soma-zone.com/LaunchControl/

最新文章

  1. Android 2016新技术
  2. 【循序渐进学Python】7.面向对象的核心——类型(上)
  3. AFNetworking请求中含有中文时程序崩溃
  4. splay入门
  5. nodejs配置与入门
  6. ASP连接MYSQL数据库
  7. Spring 初学 1
  8. Android TextView中实现点击文本超链接(无下划线)的封装类
  9. linux 系统下配置安装 java jdk 图文流程
  10. ffmpeg h265
  11. docker - 容器里安装ssh
  12. IBM Minus One 简单字符处理
  13. bzoj4904 [Ctsc2017]最长上升子序列
  14. Nginx反向代理、负载均衡、动静分离、缓存、压缩、防盗链、跨域访问
  15. 利用 SPICE 分析理解心电图前端中的右腿驱动
  16. python下载安装BeautifulSoup库
  17. solr源码分析之数据导入DataImporter追溯。
  18. 如何构建日均千万PV Web站点(二) 之~缓存为王~
  19. python pytest测试框架介绍二
  20. Spring扩展:Spring的IoC容器(注入对象的方式和编码方式)

热门文章

  1. CF集萃3
  2. js/jquery判断一个对象是否为空
  3. Yaf--个人封装yaf的框架+swoole+elasticsearch(Window+linux版)
  4. mysql分区与分表的区别
  5. 【agc019f】AtCoder Grand Contest 019 F - Yes or No
  6. [Day4] Nginx Http模块二
  7. hive作业的优化策略
  8. Java数据结构和算法(六)--二叉树
  9. UVA11389 The Bus Driver Problem
  10. json字符串和对象的相互转换