今天在看 GitHub 的 timeline 时, 看见了一个有趣的项目 2018_code_calendar_wallpaper, 这是将图灵教育所发售的编程日历电子版和壁纸结合的一个项目, 然而是 Windows 版本的, 于是我又想将他翻译成 Mac OS 的, 并且做成一个一键更换壁纸的脚本
项目地址 Github: 2018_code_calendar_wallpaper_MacOS 如果喜欢的话, 请点个 star
效果图:
turing6.jpg
依赖
- Python3
- Wand pip install wand
- ImgaeMagick
有一些同学说会出现
no module named wand
的情况, 我特意去 wand 官网查看了一下,
Wand is a Python binding of ImageMagick, so you have to install it as well
所以必须安装 ImgaeMagick, 这里只给出官网上的 Mac OS 的安装方法
- $ brew install imagemagick
- # If seam carving (Image.liquid_rescale()) is needed you have install liblqr as well
- $ brew install imagemagick --with-liblqr
- $ sudo port install imagemagick
- $ export MAGICK_HOME=/opt/local
当然, 下面的采坑经历我也给出一种安装方式, 亲测有效
- $ 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
- Ghostscript
- brew install ghostscript
即可
使用:
下载项目, 进入项目地址, 然后 python wallpaper.py 即可实现一键换壁纸, 如果你想使用自己的壁纸, 可以将项目目录下的 paper.jpg 换成你的壁纸
参考资源:
ttttmr 的 2018 编程日历壁纸
极客编程日历 2018 桌面壁纸
采坑经历:
在使用上述参考资源 2 中的脚本时, 经历了一些坑, 首先是 ImageMagick 的安装问题, 运行脚本时, 提示需要安装 ImageMagick,
brew install ImageMaick
后运行依然无效, 最终解决办法为 https://stackoverflow.com/questions/24803747/how-to-use-or-install-magickwand-on-mac-os-x
- $ 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 + 本周周数
如果有其他的问题, 可以评论私信我, 也可以关注我的新浪微博 @ninjiacoder 私信我, 也可以发邮件给我 rayzhao98@163.com
来源: http://www.jianshu.com/p/4d94b7b87028