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 Thu 20 Sep 2018, 01:50
All times are UTC - 4
 Forum index » Advanced Topics » Additional Software (PETs, n' stuff) » Utilities
SlocateGUI with apptree
Post new topic   Reply to topic View previous topic :: View next topic
Page 3 of 3 [36 Posts]   Goto page: Previous 1, 2, 3
Author Message
stemsee

Joined: 27 Jun 2013
Posts: 2262
Location: In The Way

PostPosted: Mon 01 Feb 2016, 15:38    Post subject:  

Hi all

I just added a section to slocategui for playing selected media files over a bluetooth device using mplayer backend. This assumes you have a bluetooth device configured in /etc/asound.conf . So you can play a list of files over bluetooth speaker/headset in some other room and not interfere with your local media experience. Working well! I also set F9 key to killall mpalyer for stop. When the gui asks for command to execute type btp.

Code:
elif [[ "$app" = btp ]]; then
   yaf-splash -bg blue -text "Press F9 to stop bluetooth player" &
   mplayer -ao alsa:device=btheadset  -playlist /tmp/list-"$filext".m3u &


Also added one line of code to remove blank lines from /tmp/list-"$filext".m3u
Code:
sed -i '/^$/d' /tmp/list-"$filext".m3u
Back to top
View user's profile Send private message MSN Messenger 
stemsee

Joined: 27 Jun 2013
Posts: 2262
Location: In The Way

PostPosted: Mon 22 Jan 2018, 15:39    Post subject:  

Updated to improve performance.
Also updated for fatdog mount points /aufs/devsave and /aufs/devbase
If there are any phantom drives then perform 'slocategui.sh reset' in terminal. Also do the same to completely refresh all databases.
Code:

#!/bin/sh
# slocategui.sh by stemsee copyright (c) 2014 Marcos Contant
# FatDog version
# Find files and execute commands upon them or send them to apps

slct=`busybox which slocate`
if [[ ! -z "$slct" ]]; then
   [[ ! -d /var/lib/slocate ]] && mkdir -p /var/lib/slocate
else
   yad -undecorated --no-buttons --skip-taskbar --text "The slocate binary was not found. Install slocate." --timeout 4
   exit
fi
pathdef (){
if [ -d /live ]; then
   path=media
else
   path=mnt
fi
export path
}
pathdef
extdbfn (){
   for file in `probepart -m | grep -v -e 'none' | cut -f1 -d'|' | cut -f3 -d'/' | grep -v -e 'sr0' -e 'devsave' -e 'devbase' | tr '\n' ' '`
   do
      emp=`ls -A /$path/$file/`
         if [[ -z "$emp" ]]; then
            mkdir /"$path"/"$file"
         fi
         up=`mount | grep -e 'sd[a-z][1-9]' | grep "$file"`
         if [[ -z "$up" ]]; then
            [[ `mount | grep '$file'` != devsave || `mount | grep '$file'` != devbase ]] && mount --rw /dev/"$file" /"$path"/"$file"
         fi
         if [[ ! -e /"$path"/"$file"/slocate.db ]]; then
            yad --progress --pulsate --auto-close --window-icon="" --width=300 --title "Creating Database '$file'" &
            pid1=$!
            slocate -U /"$path"/"$file"/ -o /"$path"/"$file"/slocate.db &
            chmod a+x /"$path"/"$file"/slocate.db
            kill $pid1
         elif [[ -e /"$path"/"$file"/slocate.db ]]; then
            yad --progress --pulsate --auto-close --window-icon="" --width=300 --title "Updating Database '$file'"  &
            pi=$!
            slocate -qv -o /"$path"/"$file"/slocate.db &
            chmod a+x /"$path"/"$file"/slocate.db
            kill $pi
         fi
         ln -fs /"$path"/"$file"/slocate.db /var/lib/slocate/"$file"
      done
thisdsave=`mount | grep 'devsave'`
dbaseit=`mount | grep 'devbase'`
if [[ ! -z "$thisdsave" ]]; then
   slocate -U /aufs/devsave -o /aufs/devsave/slocate.db &
   chmod a+x /aufs/devsave/slocate.db
   ln -s /aufs/devsave/slocate.db /var/lib/slocate/devsave
fi
if [[ ! -z "$dbaseit" ]]; then
   slocate -U /aufs/devbase -o /aufs/devbase/slocate.db &
   chmod a+x /aufs/devbase/slocate.db
   ln -s /aufs/devbase/slocate.db /var/lib/slocate/devbase
fi
}
extdbfn
update (){
   for i in $pathto
   do
      up=`mount | grep -e 'sd[a-z][1-9]' |  grep -v -e 'devsave' -e 'devbase' | grep "$i"`
      [[ ! -z "$up" ]] && slocate -U /"$path"/"$i" -o /"$path"/"$i"/slocate.db &
      if [[ -z "$up" ]]; then
         [[ -e /"$path"/"$i"/slocate.db ]] && rm -f /"$path"/"$i"/slocate.db
      fi
   done
}
export -f update
already=$(grep -e slocate /etc/group)
if [[ -z "$already" ]]; then
   addgroup slocate 2>/dev/null
fi
# remove databases named slocate.db
if [[ "$1" = reset ]]; then
   for file in `probepart -m | grep -v -e 'none' | cut -f1,2 -d '|' | cut -f3 -d '/' | grep -v -e 'sr0' | tr '\n' ' '`
   do
      file=`echo $file | cut -f1 -d'|'`
      fs=`echo $file | cut -f2 -d'|'`
      [[ ! -d /"$path"/"$file" ]] && mkdir /"$path"/"$file"
      sleep 2
      up=`mount | grep -e 'sd[a-z][1-11]' | grep -v -e 'devsave' -e 'devbase' | grep "$file"`
      if [[ -z "$up" ]]; then
         mount -t $fs --rw /dev/"$file" /"$path"/"$file"
         sleep 1
      fi
      [[ /"$path"/"$file"/slocate.db ]] && rm -f /"$path"/"$file"/slocate.db
   done
   thisdsave=`mount | grep 'devsave'`
dbaseit=`mount | grep 'devbase'`
if [[ ! -z "$thisdsave" ]]; then
   rm -f /aufs/devsave/slocate.db &
   rm /var/lib/slocate/devsave
fi
if [[ ! -z "$dbaseit" ]]; then
   rm -f /aufs/devbase/slocate.db &
   rm /var/lib/slocate/devbase
fi
      rm -f /var/lib/slocate/*
      [[ /tmp/result ]] && rm /tmp/result
      [[ /tmp/list-*.m3u ]] && rm /tmp/list-*.m3u
      extdbfn &
fi

# yad gui input search term
filext=`yad --window-icon="" --title="Find files" --text="Input search text:
e.g. .mp3" --entry`
   ret=$?
   [[ $ret -eq 1 ]] && exit
if [[ -z "$filext" ]]; then
   slocategui.sh &
   exit
fi
# store and format search term
echo "$filext" > /tmp/name
sed -i 's/^/nm=/' /tmp/name
# create root db and make searchable
rootdbfn (){
   yad --window-icon="" --width=300 --title="Creating Database for '/'" --progress --pulsate &
   pid=$!
   slocate -u -e /media,/aufs,/initrd,/$path -o /var/lib/slocate/system
   chmod a+x /var/lib/slocate/system
}
# has root database been created?
if [ ! -e /var/lib/slocate/system ]; then
   rootdbfn
else
   slocate -qv -o /var/lib/slocate/system &
fi
# choose database to search
pathfn (){
for F in `ls /var/lib/slocate/*`
do
    if [ -L "$F" ]; then
        if readlink -q "$F" 2>/dev/null ; then
            continue
        else
            rm /var/lib/slocate/"$F"
        fi
    fi
done
   kill $pid
   pathto=`ls /var/lib/slocate/* | grep --invert-match 'slocate.db' | yad --geometry=200x400 --list --column="Search sys or drives" --multiple --title="Find files in" --text="Which drives to search?" --window-icon="" --separator ' '`
   export pathto
}
YADPID=$(ps -eo pid,cmd | grep -v grep | grep "yad --progress" | tr ' ' '\n' | wc -l )
if [  "$YADPID" = 0 ]; then
   pathfn
fi
if [ -z "$pathto" ]; then
   exec "$0"
   exit
fi
if [[ -e "$pathto" ]]; then
   yad --splash --text " Please wait:  Now searching \n'$pathto'" --progress --pulsate &
   pid3=$!
fi
# search databases
pathto=`echo $pathto | tr ' ' ':' | tr '\n' ':'`
#part=`echo $pathto | cut -f1 -d' \n'`
slocate -i "$filext" --database="$pathto" > /tmp/"$filext"-result
# multiple file/dir selection gui
kill $pid3
select=$(cat /tmp/"$filext"-result | yad --window-icon="" --title "SlocateGUI: multiple selection" --list --multiple --center --height="400" --width="300" --column="$filext:" --print-column="1" --separator="\n")
ret=$?
[[ $ret -eq 1 ]] && slocategui.sh && exit
[[ -z "$select" ]] && slocategui.sh && exit
if [[ $ret -eq 0 ]]; then
   echo "$select" | sed '/^$/d' > /tmp/list-"$filext".m3u
# gui command to execute input box=
   prog=`yad --width=400 --window-icon="" --title="Command" --form --field="Enter command/app to execute:" -entry "" --field="playlist:CHK" "FALSE"`
   
   if [[ -z "$prog" ]]; then
      slocategui.sh &
      exit
   fi
   app=`echo "$prog" | cut -f1 -d'|'`
   #options=`echo "$prog" | cut -f2 -d'|'`
   pl=`echo "$prog" | cut -f2 -d'|'`
   yad --undecorated --no-buttons --no-focus --skip-taskbar --progress --pulsate --progress-text="Performing $app on selected" --timeout=4 &
   if [[ "$pl" = TRUE ]]; then
         "$app" /tmp/list-"$filext".m3u &  # app opens playlist
   elif [[ "$app" = rm ]]; then # delete files/dirs
      while read line
      do
         rm -rf "$line"
      done < /tmp/list-"$filext".m3u
   elif [[ "$app" = lrm ]]; then
      while read line
      do
         rm -rf "$line"
      done < /tmp/list-"$filext".m3u
   elif [[ "$app" = mv ]]; then # move files/dirs to 'gui input box'
         location=`yad --window-icon="" --geometry=250 --title="Type Path To Destination" --text="Path:
         e.g. /root/my-documents" --field="Type Path:" --entry`
      if [[ -z "$location" ]]; then
         slocategui.sh &
         exit
      fi
         while read line
         do
            mv -rf "$line" "$location"
         done < /tmp/list-"$filext".m3u
   elif [[ "$app" = replace ]]; then # replace string or symbol except apostrophe and backslash (but possible)
         replace=`yad --window-icon="" --geometry=440 --title="Format: :ReplaceThis:WithThis: " --text "But not ' nor /:" --entry`
         if [[ -z "$replace" ]]; then
            slocategui.sh &
            exit
         fi
      t1=`echo "$replace" | cut -f2 -d ":"`
      t2=`echo "$replace" | cut -f3 -d ":"`
         while read line
         do
            select2=`echo "$line" | rev | cut -f1 -d '/' | rev`
            rp=`echo "$select2" | sed "s/$t1/$t2/"`
            rename "$select2" "$rp" "$line"
         done < /tmp/list-"$filext".m3u
   elif [[ "$app" = cp ]]; then # copy files/dirs to 'gui input box'
      location=`yad --window-icon="" --geometry=260 --title="Type Path To Destination" --text="Path:
      e.g. /root/my-documents" --field="Type Path:" --entry`
         if [[ -z "$location" ]]; then
            slocategui.sh &
            exit
         fi
      while read line
      do
         cp -rf "$line" "$location"
      done < /tmp/list-"$filext".m3u
   elif [[ "$app" = ln ]]; then # link files
      while read line
      do
            linknm=`yad --window-icon="" --geometry=200 --title="Type link name" --entry`
            if [[ -z "$linknm" ]]; then
               slocategui.sh &
               exit
            fi   
         line1=`echo $select | cut -f2,3,4,5,6,7,8,9,10 -d '/'`
         ln -s "$select" /"line1"/"$linknm"
      done < /tmp/list-"$filext".m3u
   elif [[ "$app" = rename ]]; then # rename files
      while read line
      do
         newname=`yad --window-icon="" --geometry=200 --title="Type new name" --entry`
            if [[ -z "$newname" ]]; then
               slocategui.sh &
               exit
            fi
         line=`echo $select | rev | cut -f1 -d'/' | rev`
         rename "$line" "$newname" "$select"
      done < /tmp/list-"$filext".m3u
   elif [[ "$app" = viewnior ]]; then
      while read line
      do
      "$app" "$line"
      rm -f /tmp/list-"$filext".m3u
      done < /tmp/list-"$filext".m3u
   elif [[ "$app" = btp ]]; then
      mplayer -ao alsa:device=btheadset -playlist /tmp/list-"$filext".m3u &
   else
      while read line
      do
         "$app" "$line"
      done < /tmp/list-"$filext".m3u
   fi
fi
bash -c update
exec "$0" &
# open again for convenience to search new term
function finish (){
   rm -rf /tmp/result
}
export -f finish
trap finish EXIT

Last edited by stemsee on Thu 21 Jun 2018, 04:58; edited 9 times in total
Back to top
View user's profile Send private message MSN Messenger 
mikeslr


Joined: 16 Jun 2008
Posts: 2620
Location: 500 seconds from Sol

PostPosted: Mon 22 Jan 2018, 16:51    Post subject: new script  

Hi stemsee,

Am I guessing correctly that the above replaces the bash-script file named slocategui at /usr/bin?

Lest you not spend an inordinate amount of time in recriminations about not being specific, bear in mind that the only useful contributions of editors and attorneys is making certain i's are dotted and t's are crossed.

In order to see how things functioned I viewed the contents of slocateGUI-x86_64.pet.sfs. At its top-most level were etc, usr and var folders and a script named pinstall. Pinstall reads:

#!/bin/sh
echo "slocate::21:root,spot,fido
" >> /etc/group
rm -f /pinstall

I may be mistaken --always a very strong possibility-- but my impression was that if loaded as an SFS, a pinstall would not be executed and that some kind of "import" or "export" command was required. [I am abashed to have to admit that my bash in on a very primitive level]. Can you clarify?

Thanks,

mikesLr
Back to top
View user's profile Send private message 
stemsee

Joined: 27 Jun 2013
Posts: 2262
Location: In The Way

PostPosted: Mon 22 Jan 2018, 17:26    Post subject:  

Hi mikeslr

The pinstall from the package is no longer needed as this snippet of code takes care of that on first use
Code:
if [[ ! /root/.did ]]; then
   addgroup slocate 2>/dev/null
   touch /root/.did
fi


The script must now be named slocategui.sh, as that is the name it calls itself with or $0 ....

Thanks for your interest. I too am a learning, albeit very slowly indeed!

Use this app at your own risk ... I have yet to create traps in case of deleting '/' ... ha ha! I have not had any bad experiences with it and i is one of my most used apps ... that and Wifi-Scanner-2, and refdnd!

As I learn more about regex expressions and other cool stuff I will rewrite my three favourite utilities...!

cheers
stemsee
Back to top
View user's profile Send private message MSN Messenger 
mikeslr


Joined: 16 Jun 2008
Posts: 2620
Location: 500 seconds from Sol

PostPosted: Mon 22 Jan 2018, 18:10    Post subject:  

Hi Stemsee,

Learning is always fun, except when its something you have to do it, and especially when an arbitrary deadline has been set. Those are the distinguishing factors between games and work, the hallmark of civilization, and the primary reason for our discontent.

Your application is interesting for its capabilities other than "delete". Delete is something I do manually and cautiously or by accident. Shocked Surprised

mikesLr
Back to top
View user's profile Send private message 
stemsee

Joined: 27 Jun 2013
Posts: 2262
Location: In The Way

PostPosted: Thu 10 May 2018, 02:38    Post subject:  

A number of bugs fixed in the above script. Now working as intended.
Back to top
View user's profile Send private message MSN Messenger 
Display posts from previous:   Sort by:   
Page 3 of 3 [36 Posts]   Goto page: Previous 1, 2, 3
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Advanced Topics » Additional Software (PETs, n' stuff) » Utilities
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.0971s ][ Queries: 12 (0.0163s) ][ GZIP on ]