{"id":149255,"date":"2020-08-20T21:00:00","date_gmt":"2020-08-20T13:00:00","guid":{"rendered":"http:\/\/4563.org\/?p=149255"},"modified":"2020-08-20T21:00:00","modified_gmt":"2020-08-20T13:00:00","slug":"%e5%88%86%e4%ba%ab%e4%b8%aa-macos-%e8%87%aa%e5%8a%a8%e6%a3%80%e6%b5%8b%e6%98%af%e5%90%a6%e4%b8%8b%e9%9b%a8%e7%9a%84%e5%b0%8f%e5%b7%a5%e5%85%b7","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=149255","title":{"rendered":"\u5206\u4eab\u4e2a macos \u81ea\u52a8\u68c0\u6d4b\u662f\u5426\u4e0b\u96e8\u7684\u5c0f\u5de5\u5177"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u5206\u4eab\u4e2a macos \u81ea\u52a8\u68c0\u6d4b\u662f\u5426\u4e0b\u96e8\u7684\u5c0f\u5de5\u5177               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : xurunfei <\/span>  <span><i><\/i> 8<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u7531\u4e8e\u4e3b\u6bd4\u8f83\u61d2,\u60f3\u7740\u5982\u679c\u672a\u6765\u51e0\u5929\u8981\u4e0b\u96e8,\u90a3\u5c31\u81ea\u52a8\u63d0\u9192\u6211,\u4e0d\u4e0b\u96e8\u5c31\u522b\u63d0\u9192\u6211,\u901a\u77e5\u901a\u8fc7 macos \u7684\u901a\u77e5\u63d0\u9192\u7ed9\u7528\u6237 <img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/09\/20200905_5f5381506e475.png\" alt=\"\u5206\u4eab\u4e2a macos \u81ea\u52a8\u68c0\u6d4b\u662f\u5426\u4e0b\u96e8\u7684\u5c0f\u5de5\u5177\" \/><\/p>\n<h1>\u7f16\u5199\u811a\u672c<\/h1>\n<p> <\/p>\n<p>\u811a\u672c\u4ee3\u7801\u5982\u4e0b ak \u4e3a\u767e\u5ea6\u5730\u56fe\u7684\u79d8\u94a5,\u53ef\u4ee5\u81ea\u5df1\u53bb\u7533\u8bf7\u4e00\u4e2a,\u4e2a\u4eba\u7528\u514d\u8d39\u7684\u5c31\u591f\u7528\u4e86<\/p>\n<pre><code>#!\/usr\/local\/bin\/python3 # coding=utf-8  from urllib import request, parse import json from subprocess import Popen, PIPE  if __name__ == '__main__':  # \u767e\u5ea6\u5730\u56fe\u7684 ak,\u9700\u8981\u81ea\u5df1\u53bb\u7533\u8bf7     ak='xxxx'     # \u83b7\u53d6\u5730\u7406\u4f4d\u7f6e     locationUrl = \"http:\/\/api.map.baidu.com\/location\/ip?ak=%s\"%ak     response = request.urlopen(locationUrl)     read = response.read()     info = json.loads(read)     address = info[\"content\"][\"address\"]     # \u83b7\u53d6\u5929\u6c14     url = \"http:\/\/api.map.baidu.com\/telematics\/v3\/weather?output=json&amp;ak=%s&amp;location=\"%ak      response = request.urlopen(url + parse.quote(address))     response_read = response.read()     weater = json.loads(response_read)      weater_data = weater[\"results\"][0][\"weather_data\"]     # \u5224\u65ad\u662f\u5426\u4e0b\u96e8     hasWeater = False     msg = ''     msgDetail = \"\"     day = {1: '\u4eca\u5929', 2: '\u660e\u5929', 3: '\u540e\u5929', 4: '\u5927\u540e\u5929'}     i = 1     for we in weater_data:         encode = we['weather']         if '\u96e8' in encode:             hasWeater = True             msg += day[i] + ','             msgDetail += day[i] + ' : ' + encode + '   '         i += 1     msg += '\u6709\u96e8'     args = ['display notification \"' + msgDetail + '\" with title \"\u5929\u6c14\u9884\u62a5\" subtitle \"' + msg + '\"']     if hasWeater:         p = Popen(['osascript', '-e'] + args, stdin=PIPE, stdout=PIPE, stderr=PIPE)   <\/code><\/pre>\n<h1>\u6dfb\u52a0\u5b9a\u65f6\u5668,\u5b9a\u65f6\u68c0\u67e5<\/h1>\n<p> <\/p>\n<p>crontab -e \u5199\u5165<\/p>\n<pre><code>0 9,11,15,18 * * *  python3 \/User\/...\/weather.py <\/code><\/pre>\n<p>\u6ce8: \u6587\u4ef6\u5730\u5740\u9700\u8981\u5168\u8def\u5f84 \u6211\u8fd9\u91cc\u8bbe\u7f6e\u7684\u662f 9,11,15,18 \u70b9\u68c0\u67e5\u4e0b,\u53ef\u4ee5\u81ea\u5df1\u6539<\/p>\n<h1>\u8bbe\u7f6e\u6743\u9650<\/h1>\n<p> <\/p>\n<p>macos \u65b0\u7248\u672c\u9700\u8981\u7ed9 cron \u5f04\u4e0b\u6743\u9650,\u8fd9\u4e2a\u5f53\u65f6\u627e\u4e86\u6211\u597d\u4e45<\/p>\n<p>\u7cfb\u7edf\u504f\u597d\u8bbe\u7f6e &gt; \u5b89\u88c5\u6027\u4e0e\u9690\u79c1 &gt; \u5b8c\u5168\u78c1\u76d8\u8bbf\u95ee\u6743\u9650 &gt; \u9690\u79c1 &gt; \u5b8c\u5168\u7684\u78c1\u76d8\u8bbf\u95ee\u6743\u9650 \u628a \/usr\/sbin\/cron \u62d6\u8fdb\u53bb\u5c31\u597d<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>12<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"3113083\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : tslling <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u201c\u81ea\u52a8\u68c0\u6d4b\u662f\u5426\u4e0b\u96e8\u201d\uff0c\u603b\u611f\u89c9\u602a\u602a\u7684                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3113084\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : sampeng <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u51fa\u53bb\u770b\u4e00\u773c\uff0c\u5b8c\u4e8b                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3113085\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : imn1 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u672c\u6765\u60f3\u95ee\uff0c\u5982\u4f55\u5206\u8fa8\u4e0b\u96e8\u8fd8\u662f\u4e0a\u6d47\u6c34\u2026\u2026<br \/>\u8fd8\u4ee5\u4e3a\u82f9\u679c\u786c\u4ef6\u8fd8\u80fd\u505a\u8fd9\u4e8b                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3113086\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : xurunfei <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @tslling \u54c8\u54c8,\u4e0d\u8981\u5728\u610f\u8fd9\u4e9b\u7ec6\u8282<br \/>@sampeng \u672a\u6765,\u672a\u6765,\u603b\u4e0d\u80fd\u51fa\u53bb\u770b\u4e00\u773c\u672a\u6765\u5427,\u672a\u6765\u51e0\u5929\u7684\u90fd\u80fd\u770b<br \/>@imn1 \u90a3\u53ef\u4e0d\u5f97\u4e86,\u4f60\u8bf4\u7684\u5f97\u53bb\u95ee\u95ee\u6444\u50cf\u5934\u54c8\u54c8                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3113087\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : yuhangch <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u61d2\u4eba\u771f\u7684                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3113088\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lxfcool <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e4b\u524d\u4e5f\u5199\u8fc7\u7c7b\u4f3c\u7684 py, \u76f4\u5230\u67d0\u5929\u5f88\u5fd9\u6ca1\u7528\u7535\u8111, \u5bfc\u81f4\u5f53\u5929\u6ca1\u8fd0\u884c py<br \/>\u518d\u4e4b\u540e\u5c31\u6302\u5230\u670d\u52a1\u5668\u4e0a\u4e86, \u90ae\u4ef6\u63d0\u9192\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3113089\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : murmur <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fd9\u4e1c\u897f\u8ddf mac \u6709\u5565\u5173\u7cfb\uff0c\u6570\u636e\u6e90\u4e5f\u4e0d\u884c\u554a\uff0c\u81f3\u5c11\u5f97\u662f\u5f69\u4e91\u5929\u6c14\u5427                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3113090\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : murmur <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8bf4\u767d\u4e86\uff0c\u5b9e\u7528\u6027\u4e3a 0\uff0c\u6628\u5929\u5929\u6c14\u9884\u62a5\u5c31\u8bf4\u4eca\u5929\u4e0b\u5927\u96e8\uff0c\u7136\u540e\u65e9\u6668\u6539\u6210\u6674\u8f6c\u9634\u4e86\uff0c\u7ed3\u679c 5 \u70b9\u591a\u771f\u7684\u4e0b\u66b4\u96e8\u4e86\uff0c\u8279                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3113091\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : morningtzh <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5929\u6c14\u9884\u62a5\u6ca1\u4ec0\u4e48\u7528\uff0c\u53e6\u5916\u8d77\u5e8a hey Siri \u5c31\u80fd\u89e3\u51b3\u5566~~<br \/>\u5c0f\u7c73\u7684\u95f9\u949f\uff0c\u65e9\u4e0a\u95f9\u94c3\u7684\u65f6\u5019\u4e5f\u4f1a\u64ad\u62a5\u5929\u6c14\u548c\u65b0\u95fb~~                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3113092\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : xurunfei <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @murmur \u5929\u6c14\u9884\u62a5\u4e00\u76f4\u90fd\u53ea\u662f\u53c2\u8003,\u8fd8\u597d\u5427,\u50cf\u6211\u5357\u65b9,\u590f\u5929\u4f60\u5c31\u522b\u5962\u671b\u80fd\u51c6,\u4e00\u4e2a\u5c0f\u65f6\u53d8\u4e00\u6b21<br \/>@morningtzh \u4e0d\u592a\u559c\u6b22\u7528 siri \u54c8\u54c8,\u7ed9\u6211\u611f\u89c9\u6709\u70b9\u50bb\u50bb\u7684                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3113093\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : KennyMcCormick <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4ee5\u4e3a\u662f\u4eba\u5728\u5ba4\u5185\uff0c\u63d2\u4ef6\u53ef\u4ee5\u544a\u8bc9\u6211\u5ba4\u5916\u662f\u5426\u6b63\u5728\u4e0b\u96e8\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3113094\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : xurunfei <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @KennyMcCormick \u90a3\u4e5f\u53ef\u4ee5,\u7a0d\u5fae\u6539\u6539,\u6539\u4e3a\u5f53\u524d\u7684\u5929\u6c14 \u67e5\u8be2\u5c31\u884c\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u5206\u4eab\u4e2a macos \u81ea\u52a8\u68c0\u6d4b\u662f\u5426\u4e0b&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/149255"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=149255"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/149255\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=149255"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=149255"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=149255"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}