Scripting commands

Scripting commands

  • mdo  DigitalBox
  •   Scripting
  •   November 22, 2024

If you're using the Terminal application or if you would like to do some tiny scripting applications interacting with Haiku, one great possibility is to use the scripting commands.

In this article, a few use cases will be demonstrated to give you a better idea of the powerfulness of these commands.

Scripting is a way to use commands from the Terminal in order to automate some of your daily tasks.

I will not give details on how to create bash scripts, but instead I will present some of the Haiku scripting commands which can be useful in your bash scripts.

Interact

One of the first command is "alert".

Type in a Terminal the below to have the details :

alert --help

When you launch this command, it will display a nice message with an icon and with one or several buttons to interact with the user.

Suppose you would like to give the user a choice before launching a process ?

Then you will write something like this :

alert --warning "The FavoriteApp(tm) has been installed.\
Would you like to open the documentation ?" "Yes" "No"

If the user click on "Yes", then this result will be returned in the shell :

Another useful command is "filepanel".

It will let the user select a file in the system. Type the below to have the details :

filepanel --help

In case you need to let the user indicate a file before launching a specific process, then you can use :

filepanel -t "Open your file" -d $HOME

It will open a file panel window, so you can select one or several files and confirm with "Open" button :

As you can see above the Haiky logo image file has been selected.

Notify

What about providing information to the user via notification ? Yes it's possible !

For that use the command notify :

notify --help

This command let you select a notification message but also an HVIF icon to display :

notify --type information --title "Notification message" --icon /boot/home/Desktop/bomber.hvif --messageID MyMessageID "New article published on Haiku Insider !"

You should see the below notification displayed (the icon might be different) :

Great !

What about using SVG icons instead of HVIF ones ?

It's possible, you just need to install the nanosvg translator :

pkgman install nanosvgtranslator

Now type the below command to verify if it's working fine :

notify --type information --title "Notification message" --icon /system/data/icons/haiku/categories/32/applications-all.svg --messageID MyMessageID "New article published on Haiku Insider !"

You should see the below notification with this SVG icon :

Really nice, isn't it ?

Others commands

The remaining commands I would like to share are "query" and "desklink".

As its name indicates, "query" let you search for a specific file in your system :

query --help

Imagine you would like to identify all the ".pdf" files available on your system ?

Type the below : query "*.pdf"

And you will have the list of all the corresponding files :

To conclude this article, "desklink" is a nice command to add an icon of your preferred application in the Deskbar and to add a specific pop-menu if needed.

Type the below :

desklink "cmd=Active window (2s):/bin/screenshot --window --border --delay 2" "cmd=Remove replicant:desklink --remove=screenshot" /bin/screenshot

The first "cmd" in the line above indicate to create an entry in the menu named "Active window(2s)" and it will call the command "/bin/screenshot --window --border --delay 2".

It means it will take a screenshot after a delay of 2 seconds.

The second "cmd" create an entry in the menu named "Remove replicant" and it will call the command "desklink --remove=screenshot".

This second entry will remove the icon from the Deskbar.

The result is like below :

Really really nice command !

I didn't find a way to keep these Deskbar links saved when the system is restarted, so currently it's not a feature of the tool if I'm not wrong.

I hope you have find this information on the scripting commands useful.

In case you would like to know more, you can check the dedicated page on the official Haiku website named "Haiku-specific commandline applications".


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