Scripting: photo of the day

Scripting: photo of the day

  • mdo  DigitalBox
  •   Scripting
  •   December 26, 2024

Scripting on Haiku can be very powerful.

Today we will review how to use a script which is changing the default background with a photo of the day coming from Bing website.

By default the images used for the Backgrounds preference application on Haiku are static, meaning they are retrieved from what exists on your system.

What about making things a little bit more dynamic, by extending the possibility to download and define an image of the day?

For that, we will use the script provided by zumi, which is based on Bing's photo of the day, and which is available here : bing_wp.sh

Installation

Download the previous script and save it in the "/boot/home/config/non-packaged/bin/bing_wp.sh" location.

Then change the permissions so it can be executed :

cd /boot/home/config/non-packaged/bin/
chmod +x ./bing_wp.sh

How the script works

Now let's review it in details. It uses the below commands :

  • curl : to retrieve RSS feed data and download image
  • xmllint : to manipulate XML content
  • hey : to interact with Haiku applications
  • notify : to inform the user about the result

The first thing that the script is doing is defining the folder where the images will be downloaded :

You can change it to another location if needed. Then curl is retrieving the RSS data feed from Bing and retrieve the date of publication :

In order to download the image, xmllint is used to retrieve the image link and pass it to curl to do the corresponding download :

If you copy/paste the result of that line in WebPositive, you will see the below image :

Now that the image has been downloaded, that's where "hey" will take action :)

Before using hey, the Backgrounds application must be opened with the downloaded image as the first parameter :

Then complex things happen. Hey is called in order to ask to Backgrounds application to :

  • Scale to fit on the image
  • Apply the changes
  • Quit

If you do manually the action in Backgrounds, you must select the "Placement> Scale to fit" menu :

That's exactly what "hey" is asking via the "do MenuItem" call. However the complexity is that the menu call depends on the language defined in Haiku.

So the script is retrieving the locale catalog for Backgrounds based on that language :

The call will be "Scale to fit" in English, while it will be "Ajuster" in French. The last step is to notify the user that the background image has been changed :

Before I launch the script, I had the below background :

Let's call the script :

bing_wp.sh

Tada !

The new background is now using Bing's photo of the day :

If you have liked this article, you can put a like or a comment :)


Powered by Bludit - Hosted by Planet Hoster
© 2025 Haiku Insider