Haiku scripting

You seem to be using backticks instead of single quotes around the message constants ‘tgll’.

This works:
hey LaunchBox 'tgll' of View 0 of Window 0

1 Like

I think that discourse replace backticks with quotes, I’ll try you suggestion at soon as possible, tnx

Maybe a bit more explanations on why this works:

The MessageReceived code you quoted is from PadView, which is a view inside the window. So, if you send the message to the app or to the window itself, they won’t know what to do with it. You have to send it to the view where that MessageReceived function knows how to handle it.

Fortunately, the interface kit provides some support for hey, so that it is easy to find that view (that’s what “of View 0 of Window 0” will do)

1 Like

Hi, this let you to change your wallpaper randomly, I suggest to use this at boot or in loop with sleep if you want to change it every x minutes

work_dir="/boot/home/backgrounds" 

# path in which it your backgrounds are

work_file="/boot/home/random_wallpaper"

# path in which it the wallpaper is, you need to set the desktop background with any real file with such name , as the background preflet does not accept symlinks

# beware: the file you have set earlier will be overwritten by the symlinks then, therefore use a copy or file that you do not want to keep

# let's build the "database"

readarray -t rnd_file <<< `find "${work_dir}" -type f`

# create a symlink of a random entry

ln -fs "${rnd_file[$(($RANDOM%${#rnd_file[@]}))]}" ${work_file}

# the real magic, this message forces tracker to update the background in a blink

hey -o Tracker 'Tbgr'

EDIT: a friend pointed me out the existence of “readarray”, tnx Laura

3 Likes

It would be nice to have such a thing as default settings in the background preferences.

Considering that’s something you can find on linux distribs maybe it could be added as an option to the background app?

In the last 15 years nobody gave it a go: #3951 (Add "Random" feature to Backgrounds) – Haiku
Step up, step up… :slight_smile:

1 Like

And you don’t have enough experience to do it now?

Maybe. There are so many projects and so few time…
Maybe one of the recent newcomers would like to try their hand. :slight_smile:

3 Likes

Perhaps it isn’t complicated enough to get people attention. Let’s take inspiration from Clipdinger darkening feature and imagine full theme switching depending of luminosity. So, you would have a clear theme in the morning to arrive by steps to a dark theme in the evening.

1 Like

I’m sorry to come again with this topic, I’ve been trying to script Backgrounds with hey but I can’t get what I want

#! /bin/sh

auto_apply=true

# credits : https://github.com/markasoftware/bing-wallpaper-linux

bing_wp="/tmp/bing-wp-`date +%y%m%d`.jpg"

urlpath=$( \
curl "https://www.bing.com/HPImageArchive.aspx?format=rss&idx=0&n=1&mkt=en-US" \
| xmllint --xpath "/rss/channel/item/link/text()" - \
| sed 's/1366x768/1920x1080/g' \
)

curl -o ${bing_wp} "https://www.bing.com${urlpath}"
open application/x-vnd.Haiku-Backgrounds ${bing_wp}
if [ $auto_apply ] ; then
	hey application/x-vnd.Haiku-Backgrounds 'alwk' of View 0 of Window 0 # does not work
	hey application/x-vnd.Haiku-backgrounds 'scpl' of View 0 of Window 0 # does not work
	hey application/x-vnd.Haiku-Backgrounds 'aply' of View 0 of Window 0
	hey application/x-vnd.Haiku-Backgrounds 'quit'
fi

these few lines download the daily bing wallpaper, I can get to let Background open this file, apply it as a background, but the lines #19 (‘alwk’) and #20 (‘scpl’) won’t do what I’m expecting (apply it to all workspaces and do a scaled placement)
I know that these constants are defined in BackgroundsView.cpp, and that ShowImage can send a ‘scpl’ to Backgrounds and it’s accepted, where is my fault?

I don’t think that’ll work. the Backgrounds prefs cannot be opened with an image as parameter.

You could open the image in ShowImage, tell ShowImage to call Backgrounds with that image and tell Backgrounds to apply.

ShowImage $bing_wp
hey application/x-vnd.Haiku-ShowImage 'mDBG' of View 0 of Window 1
hey application/x-vnd.Haiku-Backgrounds 'aply' of View 0 of Window 0
1 Like

I can grant you it does, probably just for a mere case :face_with_peeking_eye:
But it doesn’t with
‘Backgrounds $file’

Thx for the hint, but this won’t work if there are more than one window of ShowImage, while Backgrounds can have only one.

I was just wondering how to use ‘hey’, it’s still something exoteric till nowadays to me

I have a command line tool that can change wallpapers if you can’t get hey to play nicely.

1 Like

This would make it very much easier than showhorn ShowImage and Backgrounds into working together… :slight_smile:

Unfortunately, it insists that “1:Error: Workspace not found in BMessage
File: No background set!” for all workspaces.

Here’s the debug output:

 1 $> bgswitch -d -v -w 1 list
BMessage(0x0) {
        be:bgndimginfoerasetext = bool(false)
        be:bgndimginfopath = string("/boot/home/Tumble Leaves.png", 29 bytes)
        be:bgndimginfoworkspaces = int32(0xffffffff or 4294967295)
        be:bgndimginfooffset = BPoint(x:0, y:0)
        be:bgndimginfomode = int32(0x1 or 1)
        be:bgndimginfoset = int32(0x0 or 0)
}
Workspace: 1
Error: Workspace not found in BMessage
File: No background set!
File: 
Mode: Scaled
Offset: X=0 Y=0
Text Outline: true

Hmm, I’m not sure if that’s a new issue or if that’s because I haven’t added support for setting a wallpaper on a workspace that doesn’t already have one set. It’s listed as a ToDo. I’ll look into it.

Nice, never heard of it before, any chance to have the chance to set the placement too?

That’s one of the ToDo items listed at the bottom of the github page.
“Allow changing the scaling mode, offset, and text outline”

It just hasn’t been a high priority because the backgrounds on my workspaces are all full screen with no offset needed.

1 Like

Depending on how fine your control over the background needs to be, there’s another easy way. The “~/Desktop” folder has the path to the background image to each workspace stored in an attribute. You could just exchange the image file, i.e. copy an image to the same location with the same filename and tell Tracker to reload backgrouds with:

hey Tracker 'Tbgr'
1 Like

I knew that ‘trick’, I was already using it in a script of mine, see my post of November; this time I was trying a different approach to do it, but it seems that to use ‘hey’ it requires to understand/knew better c++ and Haiku’s API than I do, so probably it’s just out of my range.