Can desktop icons be changed based on an event?

Using applications, configuring, problems
Post Reply
Message
Author
kirk22
Posts: 15
Joined: Thu 03 May 2007, 23:15

Can desktop icons be changed based on an event?

#1 Post by kirk22 »

Hello all,

I managed to get puppy 2.15CE running with OpenVPN, rdesktop and tightvnc to a server. So far so good but I'd like to put some icing on the cake.

It could take up to 5 minutes for the VPN to be established due to dynamic IPs. I'd like to find some way to notify the user that the VPN link is up and the coolest way I can think of is to change the desktop icon from a grey icon to full color. Is there any way to do that in Icewm?

Kirk

User avatar
Dougal
Posts: 2502
Joined: Wed 19 Oct 2005, 13:06
Location: Hell more grotesque than any medieval woodcut

#2 Post by Dougal »

Yes, when the vpn is established, I assume a script will finish running or something, right? All you need to do is add the appropriate SOAP code for changing the Rox icon (the "SetIcon" command).

The Rox manual has info on that.
What's the ugliest part of your body?
Some say your nose
Some say your toes
But I think it's your mind

User avatar
Flash
Official Dog Handler
Posts: 13071
Joined: Wed 04 May 2005, 16:04
Location: Arizona USA

#3 Post by Flash »

Way cool idea. Perhaps it could be incorporated into Puppy so that the "browse" icon lights up or changes color or something when Puppy has established a connection to the internet.

kirk22
Posts: 15
Joined: Thu 03 May 2007, 23:15

#4 Post by kirk22 »

Thanks. I pieced the following code together from the ROX manual. It works a treat. I'm just fumbling around here so if there's an easier way, I'm all ears.

Code: Select all

#!/bin/sh
rox --RPC << EOF
<?xml version="1.0"?>
<env:Envelope xmlns:env="http://www.w3.org/2001/12/soap-envelope">
	<env:Body xmlns="http://rox.sourceforge.net/SOAP/ROX-Filer">
		<SetIcon>
			<Path>/usr/bin/mybinary</Path>
			<Icon>/usr/local/lib/X11/pixmaps/disk.xpm</Icon>
		</SetIcon>
</env:Body>
</env:Envelope>
EOF

User avatar
Dougal
Posts: 2502
Joined: Wed 19 Oct 2005, 13:06
Location: Hell more grotesque than any medieval woodcut

#5 Post by Dougal »

kirk22 wrote:Thanks. I pieced the following code together from the ROX manual. It works a treat. I'm just fumbling around here so if there's an easier way, I'm all ears.
You will have to change the icon to the "off" icon at bootup, since this sets the "on" icon permanently.

I put the first half of the SOAP code into a variable HEAD, the second half into TAIL and then whenever I need to change an icon I just do

Code: Select all

echo -e "$HEAD\n<Path>/usr/bin/mybinary</Path>\n<Icon>$MYICON</Icon>\n$TAIL" | rox -R
(MYICON is set to the appropriate icon)

Note that to do this, you'll probably need the code that runs in the background, getting the connection running, to start with

Code: Select all

until pidof ROX-Filer >/dev/null ; do sleep 1 ; done
(so it waits for rox to start before running the SOAP command)
Then run the command that sets the "off" icon

(this will make the setting up of connection delayed by a few seconds...)
What's the ugliest part of your body?
Some say your nose
Some say your toes
But I think it's your mind

User avatar
Dougal
Posts: 2502
Joined: Wed 19 Oct 2005, 13:06
Location: Hell more grotesque than any medieval woodcut

#6 Post by Dougal »

I've had another idea: you can create a simple daemon, run from xinitrc, that checks the network status and updates the icon accordingly...
(Note that is HAS to run from xinitrc, so that it can interact with Rox. Running it from somewhere like rc.local will not work, even if you wait for Rox to start! It seems like they need to both be sub-processes of the same X session...)

Here's an example of how it should look:

Code: Select all

# time (in seconds) to pause between checks
INTERVAL=60
# icons to use
ONICON=
OFFICON=
# application the icon is assigned to
MYAPP=/usr/bin/myapp
# set initial value of status to nothing (so first round of loop will set icon)
OLDSTATUS=""

# SOAP code for setting icon:
HEAD='<?xml version="1.0"?>
<env:Envelope xmlns:env="http://www.w3.org/2001/12/soap-envelope">
 <env:Body xmlns="http://rox.sourceforge.net/SOAP/ROX-Filer">
  <SetIcon>'

TAIL='  </SetIcon>
 </env:Body>
</env:Envelope>'

# function to set the icon
# application and icon passed as parameters
set_icon(){
echo -e "$HEAD\n   <Path>$1</Path>\n   <Icon>$2</Icon>\n$TAIL" | rox -R
}

# wait for Rox to start running.
until pidof ROX-Filer >/dev/null
do sleep 1 
done
 
##### run the loop
while true ; do

 # check the network status : should tell you if it's on or off
 NEWSTATUS=(results of your test)
 
 # see if status has changed
 if [ "$NEWSTATUS" != "$OLDSTATUS" ] ;then # need to change icon
   if [ "$NEWSTATUS" = "off" ] ;then
     MYICON=$OFFICON
   else
     MYICON=$ONICON
   fi
   # set the icon
   set_icon $MYAPP $MYICON
   # update the old status
   OLDSTATUS="$NEWSTATUS"
 fi
 # uncomment the following line if to end script when connection is established
 # [ "$NEWSTATUS" = "on" ] && break
 
 # wait before checking again
 sleep $INTERVAL
done
Note 1: when you set MYICON, you can also set the interval to a different value.
For example, when the status is "off" you can set it to 10, so it checks more frequently, but when it's on, set it to a larger value, so it doesn't check so frequently.

Note 2: You can also just terminate the script the moment the network is up - I added a line to uncomment.
What's the ugliest part of your body?
Some say your nose
Some say your toes
But I think it's your mind

kirk22
Posts: 15
Joined: Thu 03 May 2007, 23:15

#7 Post by kirk22 »

Wow. I'll have to incorporate something like that in the next version.

I ended up loading OpenVPN at the end of .xinitrc. The OpenVPN start script sets the 'off' icons and when a connection is established another script sets the 'on' icons. The major drawback is that it doesn't handle real time updates and changes like your code.

Thanks again for the example. That will certainly come in handy.

Post Reply