美文网首页
macOS X发送系统通知

macOS X发送系统通知

作者: 我傻笑你跑掉 | 来源:发表于2021-01-27 10:13 被阅读0次

    osascript

    osascript是mac上执行applescript的命令。
    applescript脚本可以用来控制声音、亮度、发送通知等功能.
    此处只介绍使用此命令发送系统通知

    发送系统通知

    使用-e参数发送系统通知

    osascript -e "display notification with title \"{通知文字}"\"
    

    可以通过系统调用,在程序中发送通知

    代码演示

    下面演示pythongo调用osascript

    go

    package main
    
    import "os/exec"
    
    func main() {
        cmd := exec.Command("/usr/bin/osascript", "-e", "display notification with title \"祝你有美好的一天 :)\"")
        cmd.Run()
    }
    

    pyhton

    import os
    os.system('''/usr/bin/osascript -e 'display notification with title \"任务完毕, 祝你有美好的一天 :)\"' ''')
    

    效果截图

    image

    相关文章

      网友评论

          本文标题:macOS X发送系统通知

          本文链接:https://www.haomeiwen.com/subject/xfiozktx.html