haideralipunjabi / polybar-kdeconnect Goto Github PK
View Code? Open in Web Editor NEWKDEConnect module for Polybar
Home Page: https://blog.haideralipunjabi.com/posts/making-modules-for-polybar-shell-python/
KDEConnect module for Polybar
Home Page: https://blog.haideralipunjabi.com/posts/making-modules-for-polybar-shell-python/
Hello,
When I run polybar with the module, the following shows on my bar:
/bin/sh: 60: /home/user/git/polybar-kdeconnect/polybar-kdeconnect.sh: Syntax error: redirection unexpected
Line 60 is:
menu="$(rofi -sep "|" -dmenu -i -p "$1" -location $LOCATION -yoffset $YOFFSET -xoffset $XOFFSET -theme $THEME -width $WIDTH -hide-scrollbar -line-padding 4 -padding 20 -lines 5 <<< "Battery: $3%|Ping|Find Device|Send File|Unpair")"
I believe the issue is with the <<< operator. The script seems to be running in sh shell instead of bash. I do have bash installed, but neither #!/usr/bin/env bash
nor #!/bin/bash
affect the script.
I do have all the other dependencies installed.
My polybar config does include the space between .
and the script path.
I saw it uses rofi to display menu. I wanted to know if this can be run with standalone rofi without using polybar. If yes, can you suggest what changes I have to make to run it through commandline.
sorry if I am making a silly mistake.
when I run polybar with the module active
I get this error
warn: Invalid color in formatting tag detected: "rg.freedesktop.DBus.Error.UnknownObject%{PR", using fallback "#ffff0000". This is an issue with one of your formatting tags. If it is not, please report this as a bug. error: Failed to parse contents (reason: 1 unclosed action block(s))
on Debian using KDE
maybe being on KDE is the issue here
If I use polybar-kdeconnect module in my Polybar, the whole Polybar freezes on start and CPU usage is 100%. Trying to kill it gracefully, doesn't work: State 'stop-sigterm' timed out. Killing.
This is how I've configured in polybar config:
[module/kdeconnect]
exec=/path/to/polybar-kdeconnect.sh -d
tail=true
type=custom/script
If I try to run the script manually, this is what happens:
$ /path/to/polybar-kdeconnect.sh -d
%{A1:/path/to/polybar-kdeconnect.sh -n Error: org.freedesktop.DBus.Error.UnknownObject
No such object path '/modules/kdeconnect/devices/_xxxxxxxxxxxxxxxxxxxx_' -i _xxxxxxxxxxxxxxxxxxxx_ -p:}%{F#ff0}%{F-}%{A}|%{F#000}%{F-}|%{F#000}%{F-}
(I replaced some ID looking string with xs.)
Any ideas what could be the issue?
It seems weird to me that Polybar freezes and CPU goes to 100%. Is this a Polybar bug when a custom script with tail mode fails? Or do you have any ideas why that happens?
When I run the polybar I see this status in my polybar "/home/username/.config/polybar/scripts/polybar-kdeconnect.sh: line 56: -1: substring expression < 0
my polybar config:
[module/kdeconnect]
type = custom/script
exec = ". ~/.config/polybar/scripts/polybar-kdeconnect.sh; show_devices"
tail = true
all dependencies installed and kdeconnect works fine on my laptop. looking forward to hear from you.
I've copied module config from README to my polybar config and polybar throws error from title
My config:
;==========================================================
;
;
; ██████╗ ██████╗ ██╗ ██╗ ██╗██████╗ █████╗ ██████╗
; ██╔══██╗██╔═══██╗██║ ╚██╗ ██╔╝██╔══██╗██╔══██╗██╔══██╗
; ██████╔╝██║ ██║██║ ╚████╔╝ ██████╔╝███████║██████╔╝
; ██╔═══╝ ██║ ██║██║ ╚██╔╝ ██╔══██╗██╔══██║██╔══██╗
; ██║ ╚██████╔╝███████╗██║ ██████╔╝██║ ██║██║ ██║
; ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝
;
;
; To learn more about how to configure Polybar
; go to https://github.com/polybar/polybar
;
; The README contains a lot of information
;
;==========================================================
[colors]
;background = ${xrdb:color0:#222}
background = #99020202
background-alt = #bb040404
;foreground = ${xrdb:color7:#222}
foreground = #dfdfdf
foreground-alt = #555
primary = #fbae00
secondary = #e60053
alert = #bd2c40
[bar/example]
;monitor = ${env:MONITOR:HDMI-1}
width = 100%
height = 28
;offset-x = 1%
;offset-y = 1%
radius-bottom = 8.0
fixed-center = false
background = ${colors.background}
foreground = ${colors.foreground}
line-size = 3
line-color = #f00
#border-size = 4
border-left-size = 32
border-right-size = 32
border-color = #00000000
padding-left = 0
padding-right = 2
module-margin-left = 1
module-margin-right = 2
font-0 = Hack Nerd Font:style=Regular:pixelsize=10;1
font-1 = fixed:pixelsize=10;1
font-2 = unifont:fontformat=truetype:size=8:antialias=false;0
font-3 = siji:pixelsize=10;1
modules-left = bspwm
modules-center = xwindow
modules-right = filesystem xkeyboard memory cpu wlan temperature date powermenu
tray-position = right
tray-padding = 2
;tray-background = #0063ff
wm-restack = bspwm
;wm-restack = i3
;override-redirect = true
;scroll-up = bspwm-desknext
;scroll-down = bspwm-deskprev
;scroll-up = i3wm-wsnext
;scroll-down = i3wm-wsprev
cursor-click = pointer
cursor-scroll = ns-resize
[bar/bsp1]
inherit = bar/example
monitor = HDMI-A-0
tray-position = center
modules-right = filesystem kdeconnect gmail wlan eth
modules-center =
[bar/bsp2]
inherit = bar/example
monitor = DVI-D-0
modules-right = xkeyboard memory cpu date
tray-position = none
[module/xwindow]
type = internal/xwindow
label = %title:0:90:...%
[module/xkeyboard]
type = internal/xkeyboard
blacklist-0 = num lock
format-prefix = " "
format-prefix-foreground = ${colors.foreground-alt}
format-prefix-underline = ${colors.secondary}
label-layout = %layout%
label-layout-underline = ${colors.secondary}
label-indicator-padding = 2
label-indicator-margin = 1
label-indicator-background = ${colors.secondary}
label-indicator-underline = ${colors.secondary}
[module/filesystem]
type = internal/fs
interval = 25
mount-0 = /
label-mounted = %{F#0a81f5}%mountpoint%%{F-}: %used%/%total%
label-unmounted = %mountpoint% not mounted
label-unmounted-foreground = ${colors.foreground-alt}
[module/bspwm]
type = internal/bspwm
ws-icon-0=I;
ws-icon-1=II;
ws-icon-2=III;
ws-icon-3=IV;
ws-icon-4=V;
ws-icon-5=VI;ﭮ
ws-icon-6=VII;
ws-icon-7=VIII;
ws-icon-8=IX;
ws-icon-9=X;
label-focused = %icon%
label-focused-background = ${colors.background-alt}
label-focused-underline= ${colors.primary}
label-focused-padding = 2
label-occupied = %icon%
label-occupied-padding = 2
label-urgent = %icon%!
label-urgent-background = ${colors.alert}
label-urgent-padding = 2
label-empty = %icon%
label-empty-foreground = ${colors.foreground-alt}
label-empty-padding = 2
; Separator in between workspaces
; label-separator = |
[module/i3]
type = internal/i3
format = <label-state> <label-mode>
index-sort = true
wrapping-scroll = false
; Only show workspaces on the same output as the bar
;pin-workspaces = true
label-mode-padding = 2
label-mode-foreground = #000
label-mode-background = ${colors.primary}
; focused = Active workspace on focused monitor
label-focused = %index%
label-focused-background = ${colors.background-alt}
label-focused-underline= ${colors.primary}
label-focused-padding = 2
; unfocused = Inactive workspace on any monitor
label-unfocused = %index%
label-unfocused-padding = 2
; visible = Active workspace on unfocused monitor
label-visible = %index%
label-visible-background = ${self.label-focused-background}
label-visible-underline = ${self.label-focused-underline}
label-visible-padding = ${self.label-focused-padding}
; urgent = Workspace with urgency hint set
label-urgent = %index%
label-urgent-background = ${colors.alert}
label-urgent-padding = 2
; Separator in between workspaces
; label-separator = |
[module/cpu]
type = internal/cpu
interval = 2
format-prefix = "CPU ["
format-prefix-foreground = ${colors.foreground-alt}
format-suffix = "]"
format-suffix-foreground = ${colors.foreground-alt}
format-underline = #f90000
label = %percentage-core1:3%%%{F#555}][%{F-}%percentage-core2:3%%%{F#555}][%{F-}%percentage-core3:3%%%{F#555}][%{F-}%percentage-core4:3%%
[module/memory]
type = internal/memory
interval = 2
format-prefix = "RAM "
format-prefix-foreground = ${colors.foreground-alt}
format-underline = #4bffdc
label = %gb_used%/%gb_total%
[module/wlan]
type = internal/network
interface = wlp0s16f0u1u3
interval = 3.0
format-connected = <ramp-signal> <label-connected>
format-connected-underline = #9f78e1
label-connected = %essid%
format-disconnected =
;format-disconnected = <label-disconnected>
;format-disconnected-underline = ${self.format-connected-underline}
;label-disconnected = %ifname% disconnected
;label-disconnected-foreground = ${colors.foreground-alt}
ramp-signal-0 =
ramp-signal-foreground = ${colors.foreground-alt}
[module/eth]
type = internal/network
interface = enp4s0
interval = 3.0
format-connected-underline = #55aa55
format-connected-prefix = " "
format-connected-prefix-foreground = ${colors.foreground-alt}
label-connected = %local_ip%
format-disconnected =
[module/date]
type = internal/date
interval = 1
date = %d.%m.%Y
date-alt = "%Y-%m-%d"
time = %H:%M:%S
time-alt = %H:%M:%S
format-prefix = " "
format-prefix-foreground = ${colors.foreground-alt}
format-underline = #0a6cf5
label = %date% %{F#555}%{F-} %time%
[module/gmail]
type = custom/script
exec = ~/.config/polybar/gmail/launch.py -p -c \#555 -ns
tail = true
click-left = chromium https://mail.google.com &
format-underline = #96e900
[module/kdeconnect]
type = custom/script
exec = "~/.config/polybar/polybar-kdeconnect/polybar-kdeconnect.sh -d"
tail = true
format-underline = #FFC500
[settings]
screenchange-reload = true
;compositing-background = xor
;compositing-background = screen
;compositing-foreground = source
;compositing-border = over
;pseudo-transparency = false
; vim:ft=dosini
When activating this module, I get an idle cpu usage of 30% on all cores. Not sure why, only thing I'm sure of is that this module is the reason. Would love to find out why, but don't know where and how to look.
EDIT: Happens on both of my Computers, both running Regolith Linux (basically Ubuntu 20.04).
If no device is connected and i click the icon it fezzes my pc, only the window that had focus in i3wm works, any other thing just do not respond and i have to turn of my pc with the power button if i wanna use my pc
~/.config/polybar/cuts/polybar-kdeconnect.sh: line 56: -1: substring expression < 0 i am faching the error
Hi,
The module didn't work out of the box. The menu would show up, but none of the options did anything. I could still receive pings from my paired device and send pings via shell commands.
I took a look at the code and all the numbered bash variables ($1, $2, etc.) are off by one., e.g. the script uses $2 for the deviceid variable instead of $3. I believe this is because in line 41:
devices+="%{A1:. $DIR/polybar-kdeconnect.sh; show_menu $devicename $deviceid $battery:}$icon%{A}$SEPERATOR"
$DIR/polybar-kdeconnect.sh
is being treated as a variable.
I'm not sure why this is, or how to escape it properly. My workaround was to increment all the numbered variables, but I'd be happy to know a better way to fix it.
Hey there,
first of all, thanks for your efforts.
I have googled this issue and found a lot threads about different modules where people really forgot to configure the type and it was easy to solve.
However... i copied the snippet from this repos readme and it still doesn't seem to like it.
I literally retyped the whole thing to make sure it is not some weird unicode characters copied from github...
I also copied the "kdeconnect" from [module/kdeconnect], so that these two names are really exactly the same.
Still i get
error: Disabling module "kdeconnect" (reason: Missing parameter "module/kdeconnect.type")
i ran polybar with -l trace, but it is no more specific than this line, apparently...
Relevant parts from my config:
`
modules-left = info-pingrtt1 info-pingrtt2 network-traffic system-uptime-pretty kdeconnect
modules-center = date
modules-right = filesystem xbacklight pulseaudio memory cpu wlan eth1 eth battery temperature powermenu
[module/kdeconnect]
type = custom/script
exec = /home/sebastian/tools/polybar-kdeconnect/polybar-kdeconnect.sh -d
tail = true
`
Script it self seems to run fine when i manually start it...
Where should i look at?
All the other scripts i added were nicely cooperating ;)
I'm not sure how to trigger the rofi menu, should it show up when clicking on the icon? I see no errors when running polybar from terminal and clicking on the icon, but nothing happens.
[module/kdeconnect]
type = custom/script
exec = "~/.config/polybar/scripts/polybar-kdeconnect.sh -d"
tail = true
format-padding = 2
#!/usr/bin/env bash
# CONFIGURATION
LOCATION=0
YOFFSET=0
XOFFSET=0
WIDTH=12
WIDTH_WIDE=24
THEME=solarized
# Color Settings of Icon shown in Polybar
COLOR_DISCONNECTED='#888888' # Device Disconnected
COLOR_NEWDEVICE='#ffffff' # New Device
COLOR_BATTERY_90='#ffffff' # Battery >= 90
COLOR_BATTERY_80='#ffffff' # Battery >= 80
COLOR_BATTERY_70='#ffffff' # Battery >= 70
COLOR_BATTERY_60='#ffffff' # Battery >= 60
COLOR_BATTERY_50='#ffffff' # Battery >= 50
COLOR_BATTERY_LOW='#728cbb' # Battery < 50
# Icons shown in Polybar
ICON_SMARTPHONE=''
ICON_TABLET=''
SEPERATOR='|'
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
show_devices (){
IFS=$','
devices=""
for device in $(qdbus --literal org.kde.kdeconnect /modules/kdeconnect org.kde.kdeconnect.daemon.devices); do
deviceid=$(echo "$device" | awk -F'["|"]' '{print $2}')
devicename=$(qdbus org.kde.kdeconnect "/modules/kdeconnect/devices/$deviceid" org.kde.kdeconnect.device.name)
devicetype=$(qdbus org.kde.kdeconnect "/modules/kdeconnect/devices/$deviceid" org.kde.kdeconnect.device.type)
isreach="$(qdbus org.kde.kdeconnect "/modules/kdeconnect/devices/$deviceid" org.kde.kdeconnect.device.isReachable)"
istrust="$(qdbus org.kde.kdeconnect "/modules/kdeconnect/devices/$deviceid" org.kde.kdeconnect.device.isTrusted)"
if [ "$isreach" = "true" ] && [ "$istrust" = "true" ]
then
battery="$(qdbus org.kde.kdeconnect "/modules/kdeconnect/devices/$deviceid" org.kde.kdeconnect.device.battery.charge)"
icon=$(get_icon "$battery" "$devicetype")
devices+="%{A1:$DIR/polybar-kdeconnect.sh -n '$devicename' -i $deviceid -b $battery -m:}$icon%{A}$SEPERATOR"
elif [ "$isreach" = "false" ] && [ "$istrust" = "true" ]
then
devices+="$(get_icon -1 "$devicetype")$SEPERATOR"
else
haspairing="$(qdbus org.kde.kdeconnect "/modules/kdeconnect/devices/$deviceid" org.kde.kdeconnect.device.hasPairingRequests)"
if [ "$haspairing" = "true" ]
then
show_pmenu2 "$devicename" "$deviceid"
fi
icon=$(get_icon -2 "$devicetype")
devices+="%{A1:$DIR/polybar-kdeconnect.sh -n $devicename -i $deviceid -p:}$icon%{A}$SEPERATOR"
fi
done
echo "${devices::-1}"
}
show_menu () {
menu="$(rofi -sep "|" -dmenu -i -p "$DEV_NAME" -location $LOCATION -yoffset $YOFFSET -xoffset $XOFFSET -theme $THEME -width $WIDTH -hide-scrollbar -line-padding 4 -padding 20 -lines 5 <<< "Battery: $DEV_BATTERY%|Ping|Find Device|Send File|Browse Files|Unpair")"
case "$menu" in
*Ping) qdbus org.kde.kdeconnect "/modules/kdeconnect/devices/$DEV_ID/ping" org.kde.kdeconnect.device.ping.sendPing ;;
*'Find Device') qdbus org.kde.kdeconnect "/modules/kdeconnect/devices/$DEV_ID/findmyphone" org.kde.kdeconnect.device.findmyphone.ring ;;
*'Send File') qdbus org.kde.kdeconnect "/modules/kdeconnect/devices/$DEV_ID/share" org.kde.kdeconnect.device.share.shareUrl "file://$(zenity --file-selection)" ;;
*'Browse Files')
if "$(qdbus --literal org.kde.kdeconnect "/modules/kdeconnect/devices/$DEV_ID/sftp" org.kde.kdeconnect.device.sftp.isMounted)" == "false"; then
qdbus org.kde.kdeconnect "/modules/kdeconnect/devices/$DEV_ID/sftp" org.kde.kdeconnect.device.sftp.mount
fi
qdbus org.kde.kdeconnect "/modules/kdeconnect/devices/$DEV_ID/sftp" org.kde.kdeconnect.device.sftp.startBrowsing
;;
*'Unpair' ) qdbus org.kde.kdeconnect "/modules/kdeconnect/devices/$DEV_ID" org.kde.kdeconnect.device.unpair
esac
}
show_pmenu () {
menu="$(rofi -sep "|" -dmenu -i -p "$DEV_NAME" -location $LOCATION -yoffset $YOFFSET -xoffset $XOFFSET -theme $THEME -width $WIDTH -hide-scrollbar -line-padding 1 -padding 20 -lines 1<<<"Pair Device")"
case "$menu" in
*'Pair Device') qdbus org.kde.kdeconnect "/modules/kdeconnect/devices/$DEV_ID" org.kde.kdeconnect.device.requestPair
esac
}
show_pmenu2 () {
menu="$(rofi -sep "|" -dmenu -i -p "$1 has sent a pairing request" -location $LOCATION -yoffset $YOFFSET -xoffset $XOFFSET -theme $THEME -width $WIDTH_WIDE -hide-scrollbar -line-padding 4 -padding 20 -lines 2 <<< "Accept|Reject")"
case "$menu" in
*'Accept') qdbus org.kde.kdeconnect "/modules/kdeconnect/devices/$2" org.kde.kdeconnect.device.acceptPairing ;;
*) qdbus org.kde.kdeconnect "/modules/kdeconnect/devices/$2" org.kde.kdeconnect.device.rejectPairing
esac
}
get_icon () {
if [ "$2" = "tablet" ]
then
icon=$ICON_TABLET
else
icon=$ICON_SMARTPHONE
fi
case $1 in
"-1") ICON="%{F$COLOR_DISCONNECTED}$icon%{F-}" ;;
"-2") ICON="%{F$COLOR_NEWDEVICE}$icon%{F-}" ;;
5*) ICON="%{F$COLOR_BATTERY_50}$icon%{F-}" ;;
6*) ICON="%{F$COLOR_BATTERY_60}$icon%{F-}" ;;
7*) ICON="%{F$COLOR_BATTERY_70}$icon%{F-}" ;;
8*) ICON="%{F$COLOR_BATTERY_80}$icon%{F-}" ;;
9*|100) ICON="%{F$COLOR_BATTERY_90}$icon%{F-}" ;;
*) ICON="%{F$COLOR_BATTERY_LOW}$icon%{F-}" ;;
esac
echo $ICON
}
unset DEV_ID DEV_NAME DEV_BATTERY
while getopts 'di:n:b:mp' c
do
# shellcheck disable=SC2220
case $c in
d) show_devices ;;
i) DEV_ID=$OPTARG ;;
n) DEV_NAME=$OPTARG ;;
b) DEV_BATTERY=$OPTARG ;;
m) show_menu ;;
p) show_pmenu ;;
esac
done
Hi I'm going to try your script. When I insert module on my polybar config and I restarted polybar, my bars disappear
I think KDE removed the battery interface at some point recently. Launching the script now crashes my entire Polybar config.
qdbus reports no battery
in /modules/kdeconnect/devices/[device id], only findmyphone, ping, sftp, share, and telephony.
Parameter format_underline don't work. How to do it?
In Ubuntu you need
sudo apt get install qbus-qt5
When this module is enabled, i get the following output:
error: Failed to parse contents (reason: 1 unclosed action block(s))
error: Failed to parse contents (reason: 2 unclosed action block(s))
error: Failed to parse contents (reason: 3 unclosed action block(s))
error: Failed to parse contents (reason: 4 unclosed action block(s))
error: Failed to parse contents (reason: 5 unclosed action block(s))
error: Failed to parse contents (reason: 6 unclosed action block(s))
error: Failed to parse contents (reason: 7 unclosed action block(s))
error: Failed to parse contents (reason: 8 unclosed action block(s))
error: Failed to parse contents (reason: 9 unclosed action block(s))
error: Failed to parse contents (reason: 10 unclosed action block(s))
error: Failed to parse contents (reason: 11 unclosed action block(s))
error: Failed to parse contents (reason: 12 unclosed action block(s))
error: Failed to parse contents (reason: 13 unclosed action block(s))
error: Failed to parse contents (reason: 14 unclosed action block(s))
and so on.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.