You are not logged in.

#1 2021-01-27 12:46:12

Xwang
Member
From: EU
Registered: 2012-05-14
Posts: 410

[Solved] KDE Plasma: how to show an icon in the tray from a script?

Hi,
I have a script which execute rsync everytime I connect a pen drive to the pc.
Is it possible to show an icon in the plasma system tray when that script is running?

Last edited by Xwang (2021-01-28 11:48:58)

Offline

#2 2021-01-27 14:02:57

zpg443
Member
Registered: 2016-12-03
Posts: 313

Re: [Solved] KDE Plasma: how to show an icon in the tray from a script?

An internet search will lead you to...
https://www.maketecheasier.com/use-cust … ns-in-kde/

Offline

#3 2021-01-27 15:12:49

d_fajardo
Member
Registered: 2017-07-28
Posts: 1,686

Re: [Solved] KDE Plasma: how to show an icon in the tray from a script?

An internet search will lead you to...
https://www.maketecheasier.com/use-cust … ns-in-kde/

The link doesn't really answer the OP's question on how to trigger an icon in system tray on running his script. It just tells you how to use or modify a custom icon for the KDE apps already being used which is fairly straightforward.

Offline

#4 2021-01-27 15:27:00

karabaja4
Member
From: Croatia
Registered: 2008-09-14
Posts: 1,035
Website

Re: [Solved] KDE Plasma: how to show an icon in the tray from a script?

Maybe using yad?

#!/bin/bash

yad --notification --image=terminal &
pid=${!}
sleep 10 # do stuff
kill ${pid}

Last edited by karabaja4 (2021-01-27 15:27:22)

Offline

#5 2021-01-27 15:30:26

Xwang
Member
From: EU
Registered: 2012-05-14
Posts: 410

Re: [Solved] KDE Plasma: how to show an icon in the tray from a script?

karabaja4 wrote:

Maybe using yad?

#!/bin/bash

yad --notification --image=terminal &
pid=${!}
sleep 10 # do stuff
kill ${pid}

Thank you!
I'll try it as soon as possible!

Offline

#6 2021-01-27 16:10:31

frugal1
Member
Registered: 2020-11-16
Posts: 4

Re: [Solved] KDE Plasma: how to show an icon in the tray from a script?

karabaja4 wrote:

Maybe using yad?
...

Won't that just show yad's icon in the plasma panel? OP could make a .desktop file in ~/.local/share/applications and assign a suitable icon to that.

Offline

#7 2021-01-27 16:20:57

karabaja4
Member
From: Croatia
Registered: 2008-09-14
Posts: 1,035
Website

Re: [Solved] KDE Plasma: how to show an icon in the tray from a script?

frugal1 wrote:

Won't that just show yad's icon in the plasma panel? OP could make a .desktop file in ~/.local/share/applications and assign a suitable icon to that.

It will show the icon in the system tray defined via parameter, which I believe is what OP wanted

--image=terminal

Last edited by karabaja4 (2021-01-27 16:25:17)

Offline

#8 2021-01-27 16:51:58

ugjka
Member
From: Latvia
Registered: 2014-04-01
Posts: 1,952
Website

Re: [Solved] KDE Plasma: how to show an icon in the tray from a script?

Little Go program that does this

// save as main.go
package main

import (
	"io/ioutil"
	"log"
	"os"
	"os/exec"

	"github.com/getlantern/systray"
)

func main() {
	// First Arg: Path to an image
	icon := os.Args[1]
	// Secord Arg: Path to a script, accepts arguments
	script := os.Args[2]
	// extra args
	extra := os.Args[3:]
	data, err := ioutil.ReadFile(icon)
	if err != nil {
		log.Fatal(err)
	}
	systray.SetIcon(data)
	runner := func() {
		cmd := exec.Command(script, extra...)
		cmd.Stdout = os.Stdout
		cmd.Stderr = os.Stderr
		cmd.Stdin = os.Stdin
		err := cmd.Run()
		if err != nil {
			log.Fatal(err)
		}
		systray.Quit()
	}
	systray.Run(runner, nil)
}

Install go and go-tools
Compile it with "go build -o traycon main.go "
Put the resulting traycon executable somewhere in your PATH
Now you can execute "traycon /path/to/an/icon.png /path/to/a/script.sh"
You can pass extra arguments if your script accepts them
Stdin Stdout Stderr all accessible

EDIT: you might need the gtk3 package if you don't have it

Last edited by ugjka (2021-01-27 17:24:46)

Offline

#9 2021-01-28 11:48:19

Xwang
Member
From: EU
Registered: 2012-05-14
Posts: 410

Re: [Solved] KDE Plasma: how to show an icon in the tray from a script?

Xwang wrote:
karabaja4 wrote:

Maybe using yad?

#!/bin/bash

yad --notification --image=terminal &
pid=${!}
sleep 10 # do stuff
kill ${pid}

Thank you!
I'll try it as soon as possible!

I confirm that this approach solved my issue.
Thank you very much.

Offline

Board footer

Powered by FluxBB