0%

How Apple built dynamic wallpapers? And is it possible to create your own dynamic wallpaper for macOS? I spent some time because I would like to answer to the both above questions.
Apple如何构建动态壁纸？是否可以为macOS创建自己的动态壁纸？我花了一些时间，因为我想回答上述两个问题。

In Mojave we can choose new type of wallpaper: dynamic.

Depending on day time, system displays different wallpaper. At night it is picture of Mojave at night, during day it's picture of Mojave taken during day. So at night we have dark wallpaper at day we have light wallpaper.

All built in wallpapers in macOS we can find in folder: /Library/Desktop Pictures. Also here we can find dynamic wallpaper.

Dynamic wallpaper is saved as a HEIC file (Mojave (Dynamic).heic). More information about this type of file you can find on Wikipedia. Generally this is type of file which Apple uses in iOS devices. Photos in iOS (also live photos) are stored as a HEIC file. That kind of file can contains multiple images/thumbnails and metadata in a single file.

There is really good online tool where we can check content of Mojave wallpaper file: https://strukturag.github.io/libheif/. You can upload Mojave (Dynamic).heic file and you will see that in this single file there is 16 separate pictures taken in different day phase.

So maybe it's enough to create new HEIC file with 16 separate images and macOS will show them properly. Let's try it!

First I had to prepare 16 different images.

I know, I know - they are not impressive :-). However for our experiment they will be enough.

Now I have to prepare application which convert set of images to one HEIC file. I prepared simple console application in Swift.

Application requires that in my Documents folder I have wallpaper-new folder with 16 images (from 1.png to 16.png). I can run application and after that I have new output.heic file in the same directory.

After setting this file as a wallpaper I had only one image displayed during whole day. So it seems that this file have to contains something extra. I decided to check what metadata is inside original Mojave wallpaper. I downloaded libheif library (I modified a little bit heif-info application) and I've got below result:

Thus we can see that in the first image we have additional XMP metadata. Now I know that I have to modify a little bit my Swift application. It should also add metadata for the first image in the sequence.

Now we can set up our new file as a wallpaper. And this is the result:

It works! We can prepare our custom dynamic wallpaper! And it's pretty easy.

Now the question is: what is in the apple_desktop:solar attribute? It seems that this is something encoded in base64. We can save value of that attribute as a text file (e.g. text.base64) and run following command:

After opening decoded.txt file we can notice that it starts from: bplist00. So it seems that it's binary plist file. We can run next command:

And now in decoded.txt file we have XML with data which was prepared by Apple.

We have 16 dict elements (one for each image) with four keys:

• a - (probably) some time marker
a - （可能）一些时间标记
• i - image index
i - 图像索引
• o - ? (in current Mojave wallpaper it is always equal 0)
o - ？（在当前的Mojave壁纸中它始终等于0）
• z - some time marker
z - 一些时间标记

Unfortunately I don't know yet how to convert above float numbers to time markers. If you have some ideas please let me know. Then I will have all mandatory pieces to build macOS application which based on chosen files will generate dynamic wallpaper.

For now I can build only wallpaper which will behave exactly the same way like Apple's wallpaper.

In my previous article I described how dynamic wallpapers works. I didn't know then what some of the properties in metadata means. I asked if somebody else knows what that properties means, and I've got a response really quickly. On Twitter @zwaldowski wrote to me explanation what all properties stands for.

Thus, as I wrote previously, in HEIC file we have metadata which looks like on below snippet.

We have 16 dict elements (one for each image) with four keys:

• a - altitude
a - 海拔高度
• i - image index
i - 图像索引
• o - indicates in which desktop theme image should be displayed. 0 - displays in both mode (light/dark). 1 - displays only in light mode.
o - 表示应显示哪个桌面主题图像。0 - 以两种模式（亮/暗）显示。1 - 仅在灯光模式下显示。
• z - azimuth
z - 方位角

Thanks to altitude and azimuth w exactly know where the Sun was when image was taken.

This idea is brilliant, because thanks to this information macOS can change images differently during Summer and during Winter. System knows where the Sun is and it will choose image which was taken in similar conditions. Brilliant.

Based on that knowledge I prepared new dynamic wallpaper. Here is the video how it looks like: