Conky Question... Help Please

I am trying to get a conkybar to display my active (in Focus) application name (Window_Name). I have written the following, enormous script, and am executing the following complex conky ‘code’. All I get is an error :SPEC VIOILATION: full text is NULL. When I run the script command in terminal it works… I’m in full duh mode. :wink:

Bash:

#!/bin/bash

ps -e | grep $(xdotool getwindowpid $(xdotool getwindowfocus -f)) | grep -v grep | awk '{print $4}'

Conky:

conky.text = [[
  [
      {
	"full text": "   ${exec /home/mark/.local/share/scripts/window_name.sh}  ",
	"background": "\#8DBBBA",
      "color": "\#000000X",
      "separator": true,
      "separator_block_width": 0
    },

TIA

Is the script executable?

As an aside I think the cat /proc/$(xdotool getwindowpid $(xdotool getwindowfocus))/comm solution is cleaner than your posted pipe stream.

Use xprop on the root window and find the active window ID

#!/bin/bash

active="$(xprop -root -f _NET_ACTIVE_WINDOW 0x " \$0\\n" _NET_ACTIVE_WINDOW | cut -d' ' -f2)"
[[ $active ]] || exit 1
title=$(xprop -id "$active" -f _NET_WM_NAME 0u " \$0\\n" _NET_WM_NAME | cut -d'"' -f2)
if [[ -n $title ]]; then
	title=$(xprop -id "$active" -f WM_NAME 0u " \$0\\n" WM_NAME | cut -d'"' -f2)
	[[ $title ]] || exit 1
fi

echo "$title"

I’m no conky expert but mine looks significantly different to yours, I’ll post it later tonight after work and give yours a try on my system.

@natemaia @Head_on_a_Stick
I did have the script as an executable…
I, also, tried @natemaia 's script. I get the same error. I think the problem is somehow involved with the Conky command. And it seems so simple… :frowning:

Edit: on screen change the error changed and now looks like it is in the code @natemaia provided…

Here’s the error:
Error: Could not parse JSON (lexical error: inside a string, ‘’ occurs before a character which it may not.)

I inserted a " between two ‘’. Now I’m back to the original error.

Is #000000X an actual color specification, or did you just want black as the test color?

This is JSON format? What window manager are you using this with?

You may be missing some brackets; this is the JSON code for a conky I use with i3:

conky.text = [[

[

	{ "full_text" : "CPU:  ${cpu}%  " , "color" :
		${if_match ${cpu}>=50}"\#FF2828"${else}${if_match ${cpu}>=25}"\#D9D921"${else}"\#CDCDCD"${endif}${endif} },

	{ "full_text" : "${exec cpu_temp.pl}  ", "color" : "\#CDCDCD" },

	{ "full_text" : "MEM:  ${memperc}%  " , "color" :
		${if_match ${memperc}>=40}"\#FF2828"${else}${if_match ${memperc}>=25}"\#D9D921"${else}"\#CDCDCD"${endif}${endif} },

	{ "full_text" : "BAT0:  ${battery_percent BAT0}%  ", "color" :
	    ${if_match ${battery_percent BAT0}<=15}"\#FF2828"${else}${if_match ${battery_percent BAT0}<=25}"\#D9D921"${else}"\#CDCDCD"${endif}${endif} },

	{ "full_text" : "NET:  ${upspeed wlp1s0}    ${downspeed wlp1s0}  " , "color" : "\#CDCDCD" },

	{ "full_text" : "${time %a %e %b  %k:%M}  " , "color" : "\#CDCDCD" }

],

]];
1 Like

I am using i3 as well. Oh and yes I wanted the black… I’ll test and see if I can break your code! :wink: Thank you.

"\#000000" is black
1 Like

Here is the entire code then:

conky.config = {
	out_to_console = true,
	out_to_x = false,
	background = false,
	cpu_avg_samples = 2,
	net_avg_samples = 2,
	no_buffers = true,
	out_to_stderr = false,
	update_interval = 3.0,
	uppercase = false,
	use_spacer = 'none',

};

-- # JSON for i3bar #
-- # { "full_text" : "Up:  ${uptime_short}  " , "color" : "\#CDCDCD" }, #
-- # { "full_text" : "${loadavg}  " , "color" : "\#CDCDCD" }, #
-- # { "full_text" : "${execpi 3 /home/doug/bin/cpu-temp.pl | cut -c1-7}  ", "color" : "\#CDCDCD" },

conky.text = [[

[

	{ "full_text" : "CPU:  ${cpu}%  " , "color" :
		${if_match ${cpu}>=50}"\#FF2828"${else}${if_match ${cpu}>=25}"\#D9D921"${else}"\#CDCDCD"${endif}${endif} },

	{ "full_text" : "${exec cpu_temp.pl}  ", "color" : "\#CDCDCD" },

	{ "full_text" : "MEM:  ${memperc}%  " , "color" :
		${if_match ${memperc}>=40}"\#FF2828"${else}${if_match ${memperc}>=25}"\#D9D921"${else}"\#CDCDCD"${endif}${endif} },

	{ "full_text" : "BAT0:  ${battery_percent BAT0}%  ", "color" :
	    ${if_match ${battery_percent BAT0}<=15}"\#FF2828"${else}${if_match ${battery_percent BAT0}<=25}"\#D9D921"${else}"\#CDCDCD"${endif}${endif} },

	{ "full_text" : "NET:  ${upspeed wlp1s0}    ${downspeed wlp1s0}  " , "color" : "\#CDCDCD" },

	{ "full_text" : "${time %a %e %b  %k:%M}  " , "color" : "\#CDCDCD" }

],

]];

script to call the conkyrc - i3conkybar.sh - this is from the i3 site documentation.

################################################
# Pass colors to i3 status bar conky with JSON #
################################################
 
## Create a script in ~/bin and name it i3conkybar.sh.  
 
#!/bin/sh
 
# Send the header so that i3bar knows we want to use JSON:
echo '{ "version": 1 }'
 
# Begin the endless array.
echo '['
 
# We send an empty first array of blocks to make the loop simpler:
echo '[],'
 
# Now send blocks with information forever:
exec conky -c "$HOME/.config/i3/conkyrc"

line for bar section i3 config:

status_command $HOME/.config/i3/i3conkybar.sh

screenshot or it never happened:

@PackRat Here is my Conkybar (conkybar.sh); the one I’m trying to get an active ‘window_name’ to show up on… requisite desktop shot included… :wink:

--[[
                           
# Based on Erik Dubois' original config (http://erikdubois.be)
# and Addy's work (dots-almighty)
# Add'l Color, functional and branding changes were made by me.
# Mark Rabideau (ManyRoads)
# 

]]

conky.config = {
out_to_x = false,
own_window = false,
out_to_console = true,
background = false,
max_text_width = 0,
update_interval = 4.0,
total_run_times = 0,
short_units = true,
if_up_strictness = "address",
use_spacer = "left",
override_utf8_locale = false,
cpu_avg_samples = 2,
alignment = 'middle_top'
}

conky.text = [[
  [
#    {
#	"full text": "   ${exec 2 /home/mark/.local/share/scripts/window_name.sh}  ",
#	"background": "\#8DBBBA",
#      "color": "\#000000",
#      "separator": true,
#      "separator_block_width": 0
#    },
    {
  "full_text": "   rch i3  ",
  "color": "\#81A1C1",
  "background": "\#2F343F",
  "separator": true,
  "separator_block_width": 0
},
   
{
  "full_text": "",
  "color": "\#BFBFBF",
  "background": "\#2F343F",
  "separator": true,
  "separator_block_width": 0
},
{
  "full_text": "  ${cpu cpu0}%, ${execi 4 sensors|grep 'Core 0'|awk '{print $3}'} ",
  "background": "\#2F343F",
  "color": "\#BF616A",
  "separator": true,
  "separator_block_width": 0
},
{
  "full_text": "",
  "color": "\#BFBFBF",
  "background": "\#2F343F",
  "separator": true,
  "separator_block_width": 0
},
{
  "full_text": "  ${mem}/${memmax} ",
  "color": "\#A3BE8C",
  "background": "\#2F343F",
  "separator": true,
  "separator_block_width": 0
},
{
  "full_text": "",
  "color": "\#BFBFBF",
  "background": "\#2F343F",
  "separator": true,
  "separator_block_width": 0
},
{
  "full_text":"  ${wireless_essid wlan0}${wireless_link_qual_perc wlan0}% ",
  "color": "\#B48EAD",
  "background": "\#2F343F",
  "separator": true,
  "separator_block_width": 0
},
{
  "full_text": "",
  "color": "\#BFBFBF",
  "background": "\#2F343F",
  "separator": true,
  "separator_block_width": 0
},
{
  #arch linux
  "full_text": "  ${execi 2 amixer get Master | grep % | awk '{print $5}' | sed 's/[^0-9\%]//g' | head -n1} ",
  "color": "\#EBCB8B",
  "background": "\#2F343F",
  "separator": true,
  "separator_block_width": 0
},
{
  "full_text": "",
  "color": "\#BFBFBF",
  "background": "\#2F343F",
  "separator": true,
  "separator_block_width": 0
},
{
  "full_text": "  ${time %A ~ %d %b. %Y} ",
  "color": "\#81A1C1",
  "background": "\#2F343F",
  "separator": true,
  "separator_block_width": 0
},
{
  "full_text": "",
  "color": "\#BFBFBF",
  "background": "\#2F343F",
  "separator": true,
  "separator_block_width": 0
},
{
  "full_text": "  ${time %H:%M} ",
  "color": "\#D08770",
  "background": "\#2F343F",
  "separator": true,
  "separator_block_width": 0
},
 {
  "full_text": "",
  "color": "\#BFBFBF",
  "background": "\#2F343F",
  "separator": true,
  "separator_block_width": 0
}
  ],
]]

3 Likes

That conky variable may be wrong. I don’t think exec takes a interval number. You would want “execi 2” or maybe “execpi 2”.

The man page for conky is pretty good; scroll down to the OBJECTS/VARIABLES section and see how exec, execp etc… can be used.

I just ran your commend and still nothing works. However, when I run it from terminal as:

conky execi 1 /home/mark/.local/share/scripts/window_name.sh

Conky throws the following error:
conky: MPD error: problems getting a response from "localhost" on port 6600 : Connection refused

I just uninstalled/ reinstalled conky, to no avail. Looks like I broke something. Debugging time is upon me I guess. :wink:

Instead of your script, run that command that HOAS posted.

${exec cat /proc/$(xdotool getwindowpid $(xdotool getwindowfocus))/comm}

it should run every 4 seconds with the “update_interval = 4.0,” setting.

I just made the change and… I still get the SPEC VIOLATION:full text is NULL! error/message. I’m totally 'corn’fused.

That might be related to the amixer command you’re using. You running a firewall?

Try without that volume stanza.

mpd is not running on localhost.

$sudo fuser 6600/tcp
1 Like

I live on the edge…no firewalls for me or safety nets. :wink: I have found two posts that indicate I may be encountering an i3 bug. I will try remove amixer and stanza from my gear and try things after my con-call this pm.

The mpd issue turned out to be a corrupted .conkyrc file. I deleted the .conkyrc and that error went away. The issue with conky presenting my window_names remains; minus the mpd error.

1 Like

@manyroads , @Head_on_a_Stick , @natemaia -

The commands/scripts provided all work in conky formatted JSON:

Although firefox makes it crash and give a JSON parse error:

need to restart i3 on a desktop without firefox to get it working again.

@manyroads here’s the working conkyrc:

conky.config = {
	out_to_console = true,
	out_to_x = false,
	background = false,
	cpu_avg_samples = 2,
	net_avg_samples = 2,
	no_buffers = true,
	out_to_stderr = false,
	update_interval = 3.0,
	uppercase = false,
	use_spacer = 'none',

};

-- # JSON for i3bar #
-- # { "full_text" : "Up:  ${uptime_short}  " , "color" : "\#CDCDCD" }, #
-- # { "full_text" : "${loadavg}  " , "color" : "\#CDCDCD" }, #
-- # { "full_text" : "${execpi 3 /home/doug/bin/cpu-temp.pl | cut -c1-7}  ", "color" : "\#CDCDCD" },
-- { "full_text" : "NET:  ${upspeed wlp1s0}    ${downspeed wlp1s0}  " , "color" : "\#CDCDCD" },
--{ "full_text" : "${time %a %e %b  %k:%M}  " , "color" : "\#CDCDCD" }

conky.text = [[

[

	{ "full_text" : "${exec ps -e | grep $(xdotool getwindowpid $(xdotool getwindowfocus -f)) | grep -v grep | awk '{print $4}'}  ", "color" : "\#CDCDCD" },

	{ "full_text" : "${exec cat /proc/$(xdotool getwindowpid $(xdotool getwindowfocus))/comm}  ", "color" : "\#CDCDCD" },

	{ "full_text" : "${exec ~/.local/bin/activewindow.sh}  ", "color" : "\#33aacc" },

	{ "full_text" : "${exec ~/.local/bin/window001.sh}  ", "background" : "\#ffffff", "color" : "\#33aacc" },

	{ "full_text" : "CPU:  ${cpu}%  " , "color" :
		${if_match ${cpu}>=50}"\#FF2828"${else}${if_match ${cpu}>=25}"\#D9D921"${else}"\#CDCDCD"${endif}${endif} },

	{ "full_text" : "${exec cpu_temp.pl}  ", "color" : "\#CDCDCD" },

	{ "full_text" : "MEM:  ${memperc}%  " , "color" :
		${if_match ${memperc}>=40}"\#FF2828"${else}${if_match ${memperc}>=25}"\#D9D921"${else}"\#CDCDCD"${endif}${endif} },

	{ "full_text" : "BAT0:  ${battery_percent BAT0}%  ", "color" :
	    ${if_match ${battery_percent BAT0}<=15}"\#FF2828"${else}${if_match ${battery_percent BAT0}<=25}"\#D9D921"${else}"\#CDCDCD"${endif}${endif} }

],

]];

@natemaia script is the activewindow.sh line, yours is window001.sh.

2 Likes

Thank you! Thank you! @PackRat It works! Just to prove it, here is the required screenshot and functioning conkybar code (for anyone to use).

--[[
                               
# Based on Erik Dubois' original config (http://erikdubois.be)
# and Addy's work (dots-almighty)
# Add'l Color, functional and branding changes were made by 
# Mark Rabideau (ManyRoads)... and everything I broke was fixed 
# and made better by Packrat (many thanks!)
# 

]]

conky.config = {
	out_to_console = true,
	out_to_x = false,
	background = false,
	cpu_avg_samples = 2,
	net_avg_samples = 2,
	no_buffers = true,
	out_to_stderr = false,
	update_interval = 3.0,
	uppercase = false,
	use_spacer = 'none',

};

conky.text = [[

[
    {
    "full_text": "   rch i3  ",
    "color": "\#81A1C1",
    "background": "\#2F343F",
    "separator": true,
    "separator_block_width": 0
    }, 
    {
    "full_text": "",
    "color": "\#BFBFBF",
    "background": "\#2F343F",
    "separator": true,
    "separator_block_width": 0
    },
	{ 
	"full_text" : "      ${exec ps -e | grep $(xdotool getwindowpid $(xdotool getwindowfocus -f)) | grep -v grep | awk '{print $4}'}     ", 
	"background": "\#81A1C1",
    "color": "\#000000",
    "separator": true,
    "separator_block_width": 0
	},
	{
    "full_text": "",
    "color": "\#BFBFBF",
    "background": "\#2F343F",
    "separator": true,
    "separator_block_width": 0
    },
#	{ "full_text" : "${exec cat /proc/$(xdotool getwindowpid $(xdotool getwindowfocus))/comm}  ", "color" : "\#CDCDCD" },
#	{ "full_text" : "${exec ~/.local/bin/activewindow.sh}  ", "color" : "\#33aacc" },
#	{ "full_text" : "${exec ~/.local/bin/window001.sh}  ", "background" : "\#ffffff", "color" : "\#33aacc" },
    {
    "full_text": "  ${cpu cpu0}%, ${execi 4 sensors|grep 'Core 0'|awk '{print $3}'} ",
    "background": "\#2F343F",
    "color": "\#BF616A",
    "separator": true,
    "separator_block_width": 0
    },
    {
    "full_text": "",
    "color": "\#BFBFBF",
    "background": "\#2F343F",
    "separator": true,
    "separator_block_width": 0
    },
    {
    "full_text": "  ${mem}/${memmax} ",
    "color": "\#A3BE8C",
    "background": "\#2F343F",
    "separator": true,
    "separator_block_width": 0
    },
    {
    "full_text": "",
    "color": "\#BFBFBF",
    "background": "\#2F343F",
    "separator": true,
    "separator_block_width": 0
    },
    {
    "full_text":"  ${wireless_essid wlan0}${wireless_link_qual_perc wlan0}% ",
    "color": "\#B48EAD",
    "background": "\#2F343F",
    "separator": true,
    "separator_block_width": 0
    },
    {
    "full_text": "",
    "color": "\#BFBFBF",
    "background": "\#2F343F",
    "separator": true,
    "separator_block_width": 0
    },
    {
    "full_text": "  ${execi 2 amixer get Master | grep % | awk '{print $5}' | sed 's/[^0-9\%]//g' | head -n1} ",
    "color": "\#EBCB8B",
    "background": "\#2F343F",
    "separator": true,
    "separator_block_width": 0
    },
    {
    "full_text": "",
    "color": "\#BFBFBF",
    "background": "\#2F343F",
    "separator": true,
    "separator_block_width": 0
    },
    {
    "full_text": "  ${time %A ~ %d %b. %Y} ",
    "color": "\#81A1C1",
    "background": "\#2F343F",
    "separator": true,
    "separator_block_width": 0
    },
    {
    "full_text": "",
    "color": "\#BFBFBF",
    "background": "\#2F343F",
    "separator": true,
    "separator_block_width": 0
    },
    {
    "full_text": "  ${time %H:%M} ",
    "color": "\#D08770",
    "background": "\#2F343F",
    "separator": true,
    "separator_block_width": 0
    },
	{
    "full_text": "",
    "color": "\#BFBFBF",
    "background": "\#2F343F",
    "separator": true,
    "separator_block_width": 0
    }
],

]];
1 Like