Page 1 of 1

Problems to edit PuppyPin with bash[SOLVED]

Posted: Fri 18 Jan 2013, 09:39
by rhadon
Hi

I've written a small script to swich all desktop icons on and off by moving the mouse cursor to the left side of the desktop. For this reason I copied PuppyPin and deleted all icon lines. It works fine as long as I don't change the wallpaper (this is what I do often). So how can I delete all lines starting with "<icon" in PuppyPin with a script? I tried it for several hours but all examples I found doesn't work right for me. I'm not even able to copy PuppyPin line by line correct to PuppyPin.temp, e.g. using

for i in `cat PuppyPin`; do
echo $i >> PuppyPin.temp ;
done

Can anybody help me please?

Rolf

Re: Problems to edit PuppyPin with bash

Posted: Fri 18 Jan 2013, 11:03
by SFR
rhadon wrote:for i in `cat PuppyPin`; do
echo $i >> PuppyPin.temp ;
done
This one should work properly:

Code: Select all

while IFS='' read -r LINE; do echo "$LINE" >> PuppyPin.temp; done < PuppyPin
(it also preserves code indentation)

As for switching icons, could you describe the method you're using or post some code snippets?
And what exactly happens when the wallpaper is being changed?

Greetings!

Posted: Fri 18 Jan 2013, 12:01
by rhadon
SFR wrote:This one should work properly:

Code: Select all

while IFS='' read -r LINE; do echo "$LINE" >> PuppyPin.temp; done < PuppyPin
No, it doesn't :cry: . I think it has to do with XML, or that space is interpreted as a new line.

Using this snippet I get

Code: Select all

<?xml
version="1.0"?>
<pinboard>
<backdrop
style="Stretched">/usr/local/wallrefresh/pictures/current.jpg</backdrop>
<icon
x="288"
y="704"
label="sda6"
...
Although I wanted to post my script later, when it's more bullet proofed, here it is:

A file named icons_yesno in /usr/local/IconsYesNo:

Code: Select all

#!/bin/sh
[ ! -s /root/Choices/ROX-Filer/ppin_stat ] && echo -e -n 'STAT="original"' > /root/Choices/ROX-Filer/ppin_stat
cp /root/Choices/ROX-Filer/PuppyPin /root/Choices/ROX-Filer/PuppyPin.original

while :;
do 
	#Get cursor position
	MOUSELOC=$(echo $(xdotool getmouselocation))
	XEND=$(echo `expr index "$MOUSELOC" y`)
	let "C = $XEND - 4"
	X=$(echo ${MOUSELOC:2:$C})  

	if [ $X = 1023 ] ; then  # left side of my screen, 1024x768
	/usr/local/IconsYesNo/ppin-change
	fi

done
A 2nd file named ppin_change in /usr/local/IconsYesNo:

Code: Select all

#!/bin/sh
. /root/Choices/ROX-Filer/ppin_stat

if [ $STAT = "original" ] ; then
	cp /root/Choices/ROX-Filer/PuppyPin.striped /root/Choices/ROX-Filer/PuppyPin
	STAT="striped"
	echo -e -n 'STAT="striped"' > /root/Choices/ROX-Filer/ppin_stat
else
	cp /root/Choices/ROX-Filer/PuppyPin.original /root/Choices/ROX-Filer/PuppyPin
	STAT="original" 
	echo -e -n 'STAT="original"' > /root/Choices/ROX-Filer/ppin_stat
fi	
rox --pinboard=/root/Choices/ROX-Filer/PuppyPin 
3rd, in /root/Choices/ROX-Filer/ a copy of PuppyPin named PuppyPin.striped, where all lines beginning with <icon are deleted.

I hope, you enjoy it :D , and thanks for trying to help,

Rolf

Posted: Fri 18 Jan 2013, 13:15
by SFR
I think it has to do with XML, or that space is interpreted as a new line.
That's correct.
Strange why it works fine for me then...

I tried your scripts (I just added 'sleep 1' after line that calls .../ppinchange) and everything seems to work, except the wallpaper is not being preserved after change.
Is this the problem you have mentioned?

BTW, since xdotool is not included in most of Puppies, you can also use getcurpos:

Code: Select all

read X Y <<< `getcurpos`; echo $X $Y
HTH
Greetings!

Problems to edit PuppyPin with bash

Posted: Fri 18 Jan 2013, 13:52
by L18L
As a fan of stream editor I have been trying making comments with
sed -i '#\<icons #\<!--\<icons #' /root/Choices/Rox-Filer/PuppyPin
sed -i '#</icons>#</icons>--\>-#' $HOME/Choices/Rox-Filer/PuppyPin
but
console wrote:sed: can't read /root/Choices/Rox-Filer/PuppyPin: Datei oder Verzeichnis nicht gefunden
:roll:

Anyway this is working (back up your PuppyPin before :lol: )

Code: Select all

#!/bin/sh

aFILE=$HOME/Choices/ROX-Filer/PuppyPin

mv $aFILE $aFILE.old
while read LINE; do
 case $LINE in
  \<icon*) LINE="<!--${LINE}-->" # icons commented
 esac
 echo "$LINE" >> $aFILE
done < $aFILE.old

rox --pinboard=$aFILE # refresh desktop

Posted: Fri 18 Jan 2013, 14:47
by rhadon
SFR wrote:Strange why it works fine for me then...
OK, this problem is solved, it was caused by my save file :oops: . I don't know why, but using pfix=ram, your code snipped works as expected (also my attempts, I guess). Stupid fault :roll: .

Code: Select all

read X Y <<< `getcurpos`; echo $X $Y
Will test it later, maybe it's a better solution :wink: .
... except the wallpaper is not being preserved after change.
Is this the problem you have mentioned?
Yes. Because I use a manually striped PuppyPin (with included name of the wallpaper at this time). After changing I get this wrong wallpaper first.

@L18L
Great, your post comes just in time :D . Will test now...

Thanks,
Rolf

Posted: Fri 18 Jan 2013, 14:55
by seaside
rhadon, This copies my PuppyPin --

Code: Select all

 while read line;do echo $line >>PuppyPin.temp;done <PuppyPin 
Cheers,
s

(Note: this only works if last line is blank, which it usually is)
EDIT: forgot to add that you can also make it work if there are no blank lines by doing this

Code: Select all

  while read line || [ "$line" ];do echo $line >>PuppyPin.temp;done <PuppyPin 

Posted: Fri 18 Jan 2013, 22:02
by rhadon
@L18L
your code snipped works like a charm 8) :D . And commenting out the icon lines I like more than simlpy deleting them. Thanks very much. :D

I added it to ppin-change and it works really fine, also if I change the wallpaper. A little bit polishing and a lot of testing under different conditions, and I'll add it to Wallrefresh. If there is interest, I can also build a standalone pet.

@SFR
For me it's OK without sleep1, but I've only an old laptop for testing. Is it too sensitive for you, without the sleep command?

If you like to test the new ppin-change, here it is:

Code: Select all

#!/bin/sh
. /root/Choices/ROX-Filer/ppin_stat
if [ $STAT = "original" ] ; then
	aFILE=$HOME/Choices/ROX-Filer/PuppyPin
	mv $aFILE $aFILE.old
	while read LINE; do
		case $LINE in
		\<icon*) LINE="<!--${LINE}-->" # icons commented
		esac
		echo "$LINE" >> $aFILE
	done < $aFILE.old
	STAT="striped"
	echo -e -n 'STAT="striped"' > /root/Choices/ROX-Filer/ppin_stat
else
	cp /root/Choices/ROX-Filer/PuppyPin.old /root/Choices/ROX-Filer/PuppyPin
	STAT="original" 
	echo -e -n 'STAT="original"' > /root/Choices/ROX-Filer/ppin_stat
fi	
rox --pinboard=/root/Choices/ROX-Filer/PuppyPin 
In icons_yesno I only deleted line #4, cp /root/... .

@seaside
This part of the problem was caused by my save file and my ignorance about this possibility :oops:, but thanks anyway :wink:

Cheers,
Rolf

Posted: Sat 19 Jan 2013, 12:32
by SFR
Hey Rolf

Now we're talking. :)
For me it's OK without sleep1, but I've only an old laptop for testing. Is it too sensitive for you, without the sleep command?
Yeah, in fact it was a bit too sensitive without sleep...

A couple of other things I have changed for my personal convenience, but maybe you'll find them useful too:

1. 'while...done' loop in yesno script takes a lot of CPU res.
'sleep 0.1' right before 'done' doesn't affect functionality but reduces CPU load significantly.

2. I have also modified yesno to clean the pinborad only if the pointer is in top-left corner, because usually when I'm moving the cursor to access bottom-left menu, I'm doing it too vigorously...and icons vanishes.

3. I don't know why, but replacing/refreshing the pinboard always kills conky (it's general issue, not your script's), so I've added the following line at the end of ppinchange:

Code: Select all

[ -x /root/Startup/conky* ] && /root/Startup/conky*
Thanks for the app - it (along with Der-schutzhund's VarioMenu) reminds me some features from excellent Fences for Win (...crap, they used to have a freeware version too :? ).

Greetings!

Posted: Sat 19 Jan 2013, 18:32
by rhadon
Hi SFR,

I really appreciate your ideas and help :D .

After trying the whole day to integrate the scripts in WallRefresh, I decided to let it separate.
I was aware that it uses 3%-6% CPU with my laptop, but never thought about something like sleep 0.1. Now it's ~1%. Great 8) .

My inspiration came from Ripple, in 2008/2009 the most amazing Puppy (my point of view). It came with built in Compiz Fusion and used it not with a window manager but instead of. With Compiz it was possible to associate events to all sides of the screen and all corners. It shouldn't be a big problem to use more than one side or one corner :wink: . Maybe a GUI? We'll see.

I mark this thread as solved, but if you have other ideas or hints ...

Thanks again and cheers,
Rolf

walk the awk

Posted: Mon 25 Feb 2013, 02:39
by some1
Hi

Code: Select all

mypth='/root/Choices/ROX-Filer/PuppyPin'


if [ -f "$mypth"_old ]
then
mv "$mypth"_old "$mypth"
else
cp "$mypth" "$mypth"_old
echo "$(awk '!/<icon/&&!/<\/icon>/{print}' "$mypth"_old)">"$mypth"
fi
rox --pinboard="$mypth"
Print lines which have NEITHER <icon NOR </icon>
the exclamationmark "!" is a NEGATION

Code: Select all

!/<icon/&&!/<\/icon>/
Edit: if [ -f "$mypth" ] && [ -f "$mypth"_old ]
replaced by

Code: Select all

 if [ -f "$mypth"_old ] 

-silly me.Hopefully that wont bother you.


Cheers

Posted: Thu 05 Sep 2013, 03:42
by technosaurus
Edit: removed - wrong thread.

Posted: Thu 05 Sep 2013, 04:41
by Ted Dog
A pet would be good, nice idea.

Posted: Thu 05 Sep 2013, 16:35
by rhadon
It's here, Ted Dog :wink:

Have fun,

Rolf

SwapIcons

Posted: Fri 06 Sep 2013, 14:56
by L18L
I was having fun, too :D

moved to /usr/local/apps
added 1 parameter and 1 never hidden desktop icon

hope you like it

Posted: Fri 06 Sep 2013, 17:31
by rhadon
Hey, that's the way I like it :D .

I'm more for 'all or nothing' (icons related) but it's always good to have a choice or more.

I'll try to add another choice (mouse movement + button), hopefully this weekend. Will post it in the thread about SwapIcon.

Never before I used this 'Apps' part. Well, someting more to learn :? :lol:

Thanks L18L,

Rolf