日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python定时更换mac 超美桌面背景

發(fā)布時間:2024/1/8 python 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python定时更换mac 超美桌面背景 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

介紹

在我的博客中有一篇是抓取momentumdash的每日圖片,那么我們現(xiàn)在來把圖片設(shè)置為mac的桌面

開始

簡單介紹一下,利用python的appscript更換mac的桌面,利用mac的launchctl制定定時任務(wù)

python 代碼 launch.py

import time import requests from appscript import app, mactypesclient_id = 'aff58215-a36f-4894-9208-e1fa3d4b8d0a' today = time.strftime("%Y-%m-%d") url = 'https://api.momentumdash.com/feed/bulk?syncTypes=backgrounds&localDate={localDate}'headers = {'authorization':'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2MDY2Mzc0OTIuMCwibmJmIjoxNTc1MDE0NzkyLjAsImlzcyI6ImxvZ2luLWFwaS12MiIsInVzZXJfZ3VpZCI6IjVjNjE5N2MxLThkYmYtNGY4MS1iODI3LTIxZTg0ZTA4YzcyZSJ9.hyAjKOjjZW1dfyKXdXkHK1lLDC4Y7xEJvpetnEpCp-M','Host': 'api.momentumdash.com','Accept': '*/*','X-Momentum-ClientId': client_id,'x-momentum-clientdate': time.strftime("%Y-%m-%dT%H:%M:%S"),'X-Momentum-Version': '0.100.1','x-momentum-settings-etag': '0400bf20-0000-0000-0000-5aaf255a0000','X-Momentum-ClientDate': today,'X-Requested-With': 'XMLHttpRequest','User-Agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36','Content-Type': 'application/json','cookie': '' }if __name__ == '__main__':response = requests.get(url.format(localDate=today), headers=headers).json()# print(response)backgrounds = response['backgrounds']today_uri = backgrounds[0]['filename']tomorrow_uri = backgrounds[1]['filename']# print('today_uri={today_uri}'.format(today_uri=today_uri))# print('tomorrow_uri={tomorrow_uri}'.format(tomorrow_uri=tomorrow_uri))r = requests.get(today_uri)with open('./images/{today}.jpg'.format(today=today), 'wb') as f:f.write(r.content)f.close()app('Finder').desktop_picture.set(mactypes.File('./images/{today}.jpg'.format(today=today)))

sh 代碼 run.sh

#!/bin/sh# 記錄一下開始時間 echo `date` >> ./log.txt && # 執(zhí)行python腳本(注意前面要指定python運(yùn)行環(huán)境/usr/bin/python,根據(jù)自己的情況改變) python3 ./launch.py # 運(yùn)行完成 echo 'finish' >> ./log.txt

launchctl 配置

plist 文件 com.momentumdash.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><!-- Label唯一的標(biāo)識 --><key>Label</key><string>com.momentumdash.plist</string><!-- 指定要運(yùn)行的腳本 --><key>ProgramArguments</key><array><string>/Users/xx/momentumdash/launch.sh</string></array><!-- 指定要運(yùn)行的時間 --><key>StartCalendarInterval</key><dict><key>Minute</key><integer>00</integer><key>Hour</key><integer>10</integer></dict> <!-- 標(biāo)準(zhǔn)輸出文件 --> <key>StandardOutPath</key> <string>/Users/xx/momentumdash/run.log</string> <!-- 標(biāo)準(zhǔn)錯誤輸出文件,錯誤日志 --> <key>StandardErrorPath</key> <string>/Users/xx/momentumdash/run.err</string> </dict> </plist>

配置

  • com.momentumdash.plist 文件放在 ~/Library/LaunchAgents 下
  • 執(zhí)行文件統(tǒng)一放在/Users/xx/momentumdash/ 下
  • 在~/Library/LaunchAgents 下執(zhí)行
  • launchctl load -w com.momentumdash.plist

    總結(jié)

    以上是生活随笔為你收集整理的python定时更换mac 超美桌面背景的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。