SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2014-03-30 14:59:52

ohnonot
...again
Registered: 2012-05-22
Posts: 2,205

Change Your Application's (ugly) Taskbar Icon Programmatically!

#!/bin/bash
##################################################
#
# Usage:
#	seticon <command> <path/to/icon.png>
#
#	Input:
#		$1: application's process name/command
#	Output:
#	 	$2: icon path
#
# adapted from this:
# http://blog.chewearn.com/2010/01/18/find-window-id-of-a-process-id-in-bash-script/
# (i had to change this: xwininfo -root -children -tree -int)

APP="$1"
PID=$(pidof "$APP" | awk '{print $1}')
#~ if you write a wrapper around this that has the same name as the application it's 
#~ assigning an icon to, you have to {print $2} here!

echo "APP is now" "$APP"
echo "PID is now" $PID

# Loop windows with application's executable name
while read WID; do

	WID=`echo $WID | awk '{print $1}'`
	echo "WID is now" $WID

	#~ # hex to dec
	#~ WID=$((WID))
	#~ echo "Line 31: WID is now " $WID

	# Check window's PID is matching application's PID
	if [ `xprop -id $WID _NET_WM_PID | awk '{print $3}'` -eq $PID ]
	then
		echo "Yes it equals! Window" $WID "belongs to" "$APP"
		
		#~ hack: simply set icons for all matching windows, visible or not.
		xseticon -id "$WID" "$2"
		echo "assigned icon" "$2" "to WINID" "$WID"
	
		#~ # Check is actual visible window
		#~ if [ "`xwininfo -id $WID | grep 'IsViewable'`" != '' ] ; then
			#~ echo "this should be the final result: " $WID
			#~ return 0
		#~ fi
	fi

done < <( xwininfo -root -children -tree -int 2>/dev/null | grep -i "$APP" )

Last edited by ohnonot (2014-03-30 19:55:25)

Offline

Be excellent to each other!

#2 2014-03-30 20:33:29

porkpiehat
#! Die Hard
Registered: 2012-10-02
Posts: 1,007

Re: Change Your Application's (ugly) Taskbar Icon Programmatically!

Offline

#3 2014-10-28 18:07:27

ohnonot
...again
Registered: 2012-05-22
Posts: 2,205

Re: Change Your Application's (ugly) Taskbar Icon Programmatically!

Last edited by ohnonot (2014-10-28 18:08:40)

Offline

#4 2014-10-28 18:10:37

damo
#! gimpbanger
From: N51.5 W002.8 (mostly)
Registered: 2011-11-24
Posts: 5,434

Re: Change Your Application's (ugly) Taskbar Icon Programmatically!

Last edited by damo (2014-10-28 18:18:42)

Offline

#5 2014-10-29 04:01:01

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 4,148
Website

Re: Change Your Application's (ugly) Taskbar Icon Programmatically!

Ohnonot thank you for this, it scratches an itch I'd been leaving undealtwith for a while.

The offender for me was dillo, the minimal browser. Even after putting icons in all the approved freedesktop places I got the default icon only. xseticon was the fix.  cool

In my particular case the wrapper could be reduced to this:

#!/bin/bash
icon='/usr/share/pixmaps/dillo.png'
(sleep 0.1;xseticon -id $(xdotool search --name dillo)  "$icon") &
/usr/local/bin/dillo

But it only works for a single instance. neutral

Offline

#6 2014-10-29 04:27:58

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 4,148
Website

Re: Change Your Application's (ugly) Taskbar Icon Programmatically!

PS Unfortunately dillo doesn't disclose its PID to these x-manipulator utilities which seemed to break seticon. sad

Still, the combination of xdotool and xseticon alone seems to do it for multiple windows, with dillo at least:

#!/bin/bash
icon='/usr/share/pixmaps/dillo.png'
(sleep 0.3;for i in $(xdotool search --name dillo);do xseticon -id $i "$icon";done) &
exec /usr/local/bin/dillo "$@"

Maybe there would be issues in other cases?

Last edited by johnraff (2014-10-30 02:42:04)

Offline

#7 2014-10-29 19:26:56

ohnonot
...again
Registered: 2012-05-22
Posts: 2,205

Re: Change Your Application's (ugly) Taskbar Icon Programmatically!

Offline

#8 2014-10-30 02:39:14

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 4,148
Website

Re: Change Your Application's (ugly) Taskbar Icon Programmatically!

icon="$HOME/.icons/subl.png"

/usr/bin/subl "$@" &
PID=$1
sleep 1
seticon "sublime_text" "$icon" "$PID"

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.
Server: bleh

Debian Logo