Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Wed 16 Apr 2014, 01:25
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Problems to edit PuppyPin with bash[SOLVED]
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 2 [16 Posts]   Goto page: 1, 2 Next
Author Message
rhadon


Joined: 27 Mar 2008
Posts: 1291
Location: Germany

PostPosted: Fri 18 Jan 2013, 05:39    Post subject:  Problems to edit PuppyPin with bash[SOLVED]  

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

_________________
Ich verwende "frugal", und das ist gut so. Wink
Raspberry Pi without Puppy? No, thanks.

Last edited by rhadon on Sat 19 Jan 2013, 14:35; edited 1 time in total
Back to top
View user's profile Send private message 
SFR


Joined: 26 Oct 2011
Posts: 876

PostPosted: Fri 18 Jan 2013, 07:03    Post subject: Re: Problems to edit PuppyPin with bash  

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

This one should work properly:
Code:
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!

_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
Back to top
View user's profile Send private message 
rhadon


Joined: 27 Mar 2008
Posts: 1291
Location: Germany

PostPosted: Fri 18 Jan 2013, 08:01    Post subject:  

SFR wrote:
This one should work properly:
Code:
while IFS='' read -r LINE; do echo "$LINE" >> PuppyPin.temp; done < PuppyPin
No, it doesn't Crying or Very sad . I think it has to do with XML, or that space is interpreted as a new line.

Using this snippet I get
Code:
<?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:
#!/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:
#!/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 Very Happy , and thanks for trying to help,

Rolf

_________________
Ich verwende "frugal", und das ist gut so. Wink
Raspberry Pi without Puppy? No, thanks.
Back to top
View user's profile Send private message 
SFR


Joined: 26 Oct 2011
Posts: 876

PostPosted: Fri 18 Jan 2013, 09:15    Post subject:  

Quote:
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:
read X Y <<< `getcurpos`; echo $X $Y

HTH
Greetings!

_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
Back to top
View user's profile Send private message 
L18L

Joined: 19 Jun 2010
Posts: 2473
Location: Burghaslach, Germany somewhere also known as "Hosla"

PostPosted: Fri 18 Jan 2013, 09:52    Post subject: Problems to edit PuppyPin with bash  

As a fan of stream editor I have been trying making comments with
Quote:
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
Rolling Eyes

Anyway this is working (back up your PuppyPin before Laughing )
Code:
#!/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
Back to top
View user's profile Send private message 
rhadon


Joined: 27 Mar 2008
Posts: 1291
Location: Germany

PostPosted: Fri 18 Jan 2013, 10:47    Post subject:  

SFR wrote:
Strange why it works fine for me then...

OK, this problem is solved, it was caused by my save file Embarassed . I don't know why, but using pfix=ram, your code snipped works as expected (also my attempts, I guess). Stupid fault Rolling Eyes .

Quote:
Code:
read X Y <<< `getcurpos`; echo $X $Y

Will test it later, maybe it's a better solution Wink .

Quote:
... 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 Very Happy . Will test now...

Thanks,
Rolf

_________________
Ich verwende "frugal", und das ist gut so. Wink
Raspberry Pi without Puppy? No, thanks.
Back to top
View user's profile Send private message 
seaside

Joined: 11 Apr 2007
Posts: 878

PostPosted: Fri 18 Jan 2013, 10:55    Post subject:  

rhadon, This copies my PuppyPin --

Code:
 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:
  while read line || [ "$line" ];do echo $line >>PuppyPin.temp;done <PuppyPin
Back to top
View user's profile Send private message 
rhadon


Joined: 27 Mar 2008
Posts: 1291
Location: Germany

PostPosted: Fri 18 Jan 2013, 18:02    Post subject:  

@L18L
your code snipped works like a charm Cool Very Happy . And commenting out the icon lines I like more than simlpy deleting them. Thanks very much. Very Happy

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:
#!/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 Embarassed, but thanks anyway Wink

Cheers,
Rolf

_________________
Ich verwende "frugal", und das ist gut so. Wink
Raspberry Pi without Puppy? No, thanks.
Back to top
View user's profile Send private message 
SFR


Joined: 26 Oct 2011
Posts: 876

PostPosted: Sat 19 Jan 2013, 08:32    Post subject:  

Hey Rolf

Now we're talking. Smile
Quote:
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:
[ -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 Confused ).

Greetings!

_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
Back to top
View user's profile Send private message 
rhadon


Joined: 27 Mar 2008
Posts: 1291
Location: Germany

PostPosted: Sat 19 Jan 2013, 14:32    Post subject:  

Hi SFR,

I really appreciate your ideas and help Very Happy .

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 Cool .

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.
Back to top
View user's profile Send private message 
some1

Joined: 17 Jan 2013
Posts: 17

PostPosted: Sun 24 Feb 2013, 22:39    Post subject: walk the awk  

Hi


Code:
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:
!/<icon/&&!/<\/icon>/


Edit: if [ -f "$mypth" ] && [ -f "$mypth"_old ]
replaced by
Code:
 if [ -f "$mypth"_old ]

-silly me.Hopefully that wont bother you.


Cheers
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4133

PostPosted: Wed 04 Sep 2013, 23:42    Post subject:  

Edit: removed - wrong thread.
_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
Ted Dog


Joined: 13 Sep 2005
Posts: 2049
Location: Heart of Texas

PostPosted: Thu 05 Sep 2013, 00:41    Post subject:  

A pet would be good, nice idea.
Back to top
View user's profile Send private message 
rhadon


Joined: 27 Mar 2008
Posts: 1291
Location: Germany

PostPosted: Thu 05 Sep 2013, 12:35    Post subject:  

It's here, Ted Dog Wink

Have fun,

Rolf

_________________
Ich verwende "frugal", und das ist gut so. Wink
Raspberry Pi without Puppy? No, thanks.
Back to top
View user's profile Send private message 
L18L

Joined: 19 Jun 2010
Posts: 2473
Location: Burghaslach, Germany somewhere also known as "Hosla"

PostPosted: Fri 06 Sep 2013, 10:56    Post subject: SwapIcons
Subject description: 1.1
 

I was having fun, too Very Happy

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

hope you like it
SwapIcons-1.1.png
 Description   
 Filesize   31.2 KB
 Viewed   144 Time(s)

SwapIcons-1.1.png

SwapIcons-1.1.pet
Description 
pet

 Download 
Filename  SwapIcons-1.1.pet 
Filesize  2.4 KB 
Downloaded  116 Time(s) 
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 2 [16 Posts]   Goto page: 1, 2 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1026s ][ Queries: 13 (0.0087s) ][ GZIP on ]