Problems to edit PuppyPin with bash[SOLVED]

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
rhadon
Posts: 1292
Joined: Thu 27 Mar 2008, 11:05
Location: Germany

Problems to edit PuppyPin with bash[SOLVED]

#1 Post 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
Last edited by rhadon on Sat 19 Jan 2013, 18:35, edited 1 time in total.
Ich verwende "frugal", und das ist gut so. :wink:
Raspberry Pi without Puppy? No, thanks.

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

Re: Problems to edit PuppyPin with bash

#2 Post 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!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

User avatar
rhadon
Posts: 1292
Joined: Thu 27 Mar 2008, 11:05
Location: Germany

#3 Post 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
Ich verwende "frugal", und das ist gut so. :wink:
Raspberry Pi without Puppy? No, thanks.

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#4 Post 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!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

Problems to edit PuppyPin with bash

#5 Post 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

User avatar
rhadon
Posts: 1292
Joined: Thu 27 Mar 2008, 11:05
Location: Germany

#6 Post 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
Ich verwende "frugal", und das ist gut so. :wink:
Raspberry Pi without Puppy? No, thanks.

seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#7 Post 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 

User avatar
rhadon
Posts: 1292
Joined: Thu 27 Mar 2008, 11:05
Location: Germany

#8 Post 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
Ich verwende "frugal", und das ist gut so. :wink:
Raspberry Pi without Puppy? No, thanks.

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#9 Post 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!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

User avatar
rhadon
Posts: 1292
Joined: Thu 27 Mar 2008, 11:05
Location: Germany

#10 Post 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
Ich verwende "frugal", und das ist gut so. :wink:
Raspberry Pi without Puppy? No, thanks.

some1
Posts: 117
Joined: Thu 17 Jan 2013, 11:07

walk the awk

#11 Post 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

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#12 Post by technosaurus »

Edit: removed - wrong thread.
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
Ted Dog
Posts: 3965
Joined: Wed 14 Sep 2005, 02:35
Location: Heart of Texas

#13 Post by Ted Dog »

A pet would be good, nice idea.

User avatar
rhadon
Posts: 1292
Joined: Thu 27 Mar 2008, 11:05
Location: Germany

#14 Post by rhadon »

It's here, Ted Dog :wink:

Have fun,

Rolf
Ich verwende "frugal", und das ist gut so. :wink:
Raspberry Pi without Puppy? No, thanks.

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

SwapIcons

#15 Post 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
Attachments
SwapIcons-1.1.png
(31.2 KiB) Downloaded 397 times
SwapIcons-1.1.pet
(2.4 KiB) Downloaded 454 times

User avatar
rhadon
Posts: 1292
Joined: Thu 27 Mar 2008, 11:05
Location: Germany

#16 Post 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
Ich verwende "frugal", und das ist gut so. :wink:
Raspberry Pi without Puppy? No, thanks.

Post Reply