laitimes

To implement the top macOS features, I only used 60 lines of code!

Today, let's talk about a deceptively simple but very special feature on macOS - the dynamic desktop.

Since the official launch of macOS 10.14 (Mojave), dynamic desktops have joined the bandwagon.

Whether it's from Apple's own description or from the user's perception of it, the dynamic desktop is nothing more than a video wallpaper that subtly changes as the day moves from morning to afternoon to evening.

However, if you look closely at the details of it, you will find that it is not as simple as you think.

Dynamic desktops must not only consider the single dimension of time, but also the four seasons, weather, latitude and longitude, length of day and night, and so on.

At present, there are already many Windows tools imitating this function, today, I will teach you how to achieve a dynamic desktop through 60 lines of Python.

Preparations

Before we can officially code, we need to first do 2 necessary preparations:

Weather

wallpaper

Since the dynamic desktop to be developed today is adaptive to change with the weather and time, there is no doubt that the current weather conditions need to be obtained.

Here, I get weather data through a free API() that provides 1 million calls per month and 60 per minute per month.

After accessing the above link, register a free API key, generate a long string, copy and save the API key, which will be used during development.

Next, it's time to get wallpapers.

Save the photo of each weather and time you want in the folder you want (just make sure to remember your absolute path and save it in path_to_photos variables).

Also, make sure that the name of the photo corresponds to the weather, for example, thunderstorm, named, if it snow, named, and so on.

Implementation method

First, you need to put the weather API key and wallpaper you got earlier in the variables:

Then, get another 2 important privacys that determine the live wallpaper: time and location:

Below, request and get weather conditions based on the registered weather API:

Next, normalize the obtained weather to correspond to the wallpaper we prepared:

Finally, perform the action set as wallpaper:

In this way, we obtained the location, time, weather, and successfully set the wallpaper as wallpaper.

Boots up

The core code has been written, and now we have a problem in front of us: how to make the code run in real time and dynamically change the wallpaper?

Obviously, we can't manually execute the code every time to get the time, place, weather, and change the wallpaper non-automatically.

If you can package it into a tool and start it with the computer booting, then this problem will be solved!

To implement the top macOS features, I only used 60 lines of code!

Here, we first need to use the auto-py-to-exe toolkit, which is a toolkit that can package Python's py file into exe executable files, which can be easily installed and used:

After packaging into an exe file, the next step is to set it to boot and start, this question can be searched for many answers on the network, in order to avoid everyone stepping on the pit, I also provide you with a reliable method here.

To implement the top macOS features, I only used 60 lines of code!

Opens the Run dialog box

Enter in the dialog box so that the "Startup Folder" will open

Copy the packaged file icon and paste it into a folder

That way, whenever you start your PC, the programs you need will run. To remove it from startup, just repeat the above steps to remove the item from the startup folder.

Read on