Mac Python实用工具开发记录
来源:互联网 发布:sql server log工具 编辑:程序博客网 时间:2024/05/16 02:11
1. Python在Mac上弹出消息提示
首先需要知道Mac上面弹出消息的方式:
- 调用通知中心弹出消息
osascript -e 'display notification "内容" with title "标题"'
- 调用某应用弹出消息
osascript -e 'tell app "Mail" to display dialog "该发周报了!" with title "提示"
其中Mail可以改为对应的app名称(非Launchpad上显示的名称,而是 ‘xxx.app’中’.app’前面的名称)
- 调用通知中心弹出消息
然后在python中使用如下命令便可弹出提示
import osos.system("""<osascript command>""")
2.在Mac上定时执行.py文件
这里需要用的是 ‘launchctl’ launchctl help
cd ~/Library/LaunchAgents
sudo touch com.example.hello.plist
sudo chmod 777 com.tim.shadow.autoruner.plist
在 com.tim.shadow.autoruner.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>StartCalendarInterval</key> <dict> <key>Minute</key> <integer>30</integer> <key>Hour</key> <integer>16</integer> </dict> <key>ProgramArguments</key> <array> <string>/YourPath/Example.py</string> </array> <key>KeepAlive</key> <false/> <key>Label</key> <string>com.example.hello.plist</string> <key>StandardOutPath</key> <string>/YourLogPath/examplelog.log</string> <key>StandardErrorPath</key> <string>/YourLogPath/exampleerrlog.log</string></dict></plist>
这里的内容是说,在每天的16:40时执行/YourPath/Example.py
文件,并将日志输入到/YourLogPath/examplelog.log
将错误日志输出到/YourLogPath/exampleerrlog.log
plist的日志文件必须为可以读写,否则会出现错误,导致python 脚本不能正确执行
plist详细的配置说明请参考官方说明文档
plist官方说明文档请点击
加载服务 launchctl load com.example.hello.plist
launchctl start com.example.hello.plist
停止服务可以使用: launchctl stop com.example.hello.plist
launchctl unload com.example.hello.plist
查看当前服务状态: launchctl list | grep com.example.hello.plist
若Status为0 Pid为 ‘-‘表示服务已经成功启动,但是暂未运行
若Status为0 Pid为数字 表示服务已经启动,正在运行
若Status为非0 表示服务可能出现问题,需要检查是否正确
- Mac Python实用工具开发记录
- Mac 实用工具
- Mac实用工具
- MAC实用工具
- 实用工具网址记录
- MAC OS python 配置记录
- Python实用工具介绍
- python实用工具集
- Mac开发者必备实用工具推荐
- Mac开发者必备实用工具推荐
- Mac实用工具网络引导失败
- Mac开发者必备实用工具推荐
- Mac开发者必备实用工具推荐
- 网站开发实用工具
- Drupal 7 开发实用工具
- iOS 开发实用工具
- iOS 开发实用工具
- iOS 开发实用工具
- 【转载】《计算机教育》专题报道:从一个教育实例,看信息技术对教育的影响
- 关于建表的补充
- 2017华为面试算法题小结
- 深度学习框架Caffe配置:Ubuntu 16.04+CUDA8.0+cuDNN5.1+OpenCV3.1+Anaconda+Octave4.0.3
- Android 工程签名打包时报错
- Mac Python实用工具开发记录
- CAS与sun.misc.Unsafe
- ThinkPHP如何给网页加公共的header文件和footer文件
- Alamofire网络库基础教程
- java 常用加密解密算法汇总(一)
- 6大设计原则
- Android面试题整理
- VS2012旗舰版下载地址和安装密钥
- 宽字符处理函数函数与普通函数对照表