RayZhao1998 / 2018_code_calendar_wallpaper_MacOS

your favorite wallpaper + code calendar = code calendar wallpaper

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

2018编程日历壁纸Mac OS

今天看见了ttttmr2018编程日历壁纸,无奈人家是Windows的,于是自己写了一个Mac OS一键换编程日历壁纸的python脚本。

效果图:

一键换壁纸动图展示

依赖

  • Python3
  • ImgaeMagick

有一些同学说会出现no module named wand的情况,我特意去wand官网查看了一下,Wand is a Python binding of ImageMagick, so you have to install it as well所以必须安装ImgaeMagick,但由于现在pip上面的Wand仅支持imagemagick6,而homebrew等版本默认为7。

$ brew install imagemagick@6
$ echo 'export PATH="/usr/local/opt/imagemagick@6/bin:$PATH"' >> ~/.bash_profile
$ brew link imagemagick@6 --force
  • Wand
pip install -r requirements.txt
  • Ghostscript brew install ghostscript即可

使用:

下载项目,进入项目地址,然后python wallpaper.py即可实现一键换壁纸,如果你想使用自己的壁纸,可以将项目目录下的paper.jpg换成你的壁纸。

参考资源:

  1. ttttmr2018编程日历壁纸
  2. 极客编程日历2018桌面壁纸

采坑经历:

$ brew uninstall --force imagemagick

$ brew install imagemagick@6

$ echo 'export PATH="/usr/local/opt/imagemagick@6/bin:$PATH"' >> ~/.bash_profile

$ brew link imagemagick@6 --force
  • 在"一键换壁纸",一直不知道Mac OS除了在系统设置中换壁纸外其他的方法,后来找到了一篇文章Shell系列 - Mac OS X自动下载切换桌面壁纸,于是照猫画虎,在python中使用了os.system("osascript -e \"tell application \\\"Finder\\\" to set desktop picture to POSIX file \\\"/Users/apple/Desktop/Wallpaper/" + OUTPUT + "\\\"\"")以实现“一键换壁纸”的效果。但"一键换壁纸"的命令中壁纸的地址必须使用绝对路径,所以还得通过os.getced()获取当前路径,所以最后的代码为:
address = os.getcwd() + "/" + OUTPUT 
os.system("osascript -e \"tell application \\\"Finder\\\" to set desktop picture to POSIX file \\\"" + address + "\\\"\"")
  • 由于壁纸的大小不同,可能会导致脚本运行后得到的日历壁纸在屏幕显示中不太正常,如有需要可以自己更改脚本中的参数: MARGIN_LEFT,MARGIN_TOP以及resolution

  • 当同一图片文件发生改变,再使用上述“一键换壁纸”命令时发现,壁纸并不会发生改变,为了使得每周使用者在使用该脚本时正常使用,特意改变输出文件的文件名为turing+本周周数。

About

your favorite wallpaper + code calendar = code calendar wallpaper


Languages

Language:Python 100.0%