How to set puppy linux to beep/play sound on window popup ?

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
george2002
Posts: 22
Joined: Mon 20 Sep 2010, 19:08

How to set puppy linux to beep/play sound on window popup ?

#1 Post by george2002 »

Hello there,
i have question - is there and chance to play a sound(mp3/wav etc) or simply system beep when specific window popup ? i need this option because in jdownloader (nice application for downloading from rapidshare etc witch has captcha recognition) when program can't recognize the captcha then he popups window with you can type recognized letters from captch but i wanted to have sound when this window appers - because i don't want to sit all day and watch when it appears, it would be more simply to have sound when this window appear.
Asumming is there and possibility to play sound if you get a popup window in puppy ? (i have installed version 4.1 but if this can help i can install 5.1)

Thx in advance for any solution
george2002

User avatar
Ian
Official Dog Handler
Posts: 1234
Joined: Wed 04 May 2005, 12:00
Location: Queensland

#2 Post by Ian »

I would suggest that you look at the JDownloader site and see if there is a Java add-on that would do what you wish.

george2002
Posts: 22
Joined: Mon 20 Sep 2010, 19:08

#3 Post by george2002 »

Ian wrote:I would suggest that you look at the JDownloader site and see if there is a Java add-on that would do what you wish.
Ian thx for reply :)
I done that before posting this topic on this friendly forum :)
I even write suggestion for that type of plugin/option but i get ansfer that this can't be done now because there are more important things than my sugestion :(
In my opinion there is a way to do this that when window popup then make any sound but as i mentioned i'm beginner in linux :(
If anyone have any proposition or suggestion or ready solution that could be awesome :) - for me and for other users who missing this option

PS
Some guy from jdownloader forum suggestrd me i can try that code:
The PS command (with the appropriate parameters) allows you to list information about all of the processes (and I think threads). If you grep the output of ps -e (I think) grep will return a different value when it finds an occurrence than when it does not.

It has been years since I did this, so this is probably not right (the parameters changed) You are looking for a script something like:

Code: Select all


while (`ps -e | grep "java.*"') {
    if (`ps -e --windowtitle | grep "*.?\Please Enter"') beep 700 2
    sleep 2
    }
sleep sleeps up to that number of seconds. It is like cron in that it uses the end of a second to update, rather than the passage of time. So `sleep 2` should sleep 1 to 2 seconds.

If the beep parameters are as I remember them, this is a request for a 2 second beep at 700Hz (A above middle C). That is the same frequency as most beeping alarm clocks. Almost nobody can sleep through it. We used to play songs by using beep followed by pairs of numbers.

Note that the conditionals are enclosed in accent characters ` ` so that they will be interpreted each time. This would be more efficient in TEMACS or AWK, but a lot harder to write.

As to regular expressions, they have changed a little over the years. Look at the documentation in the JDownloader Wiki.
but how can i use it ? i must create some file with that code and then run it ?

Thx for any help
george2002

george2002
Posts: 22
Joined: Mon 20 Sep 2010, 19:08

#4 Post by george2002 »

Any suggestions ?

George2002

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

#5 Post by Flash »

I don't know how to try out that code, but if I were to attempt it, I'd do it while running Puppy entirely in RAM (boot from a live CD with puppy pfix=ram boot option, or, better yet, from a multisession CD or DVD.) Running entirely in RAM means you can try things out without so much risk of borking your hd installation. Once you get your project to work, then you boot from hd and install it. :)

george2002
Posts: 22
Joined: Mon 20 Sep 2010, 19:08

#6 Post by george2002 »

Code: Select all

I don't know how to try out that code, but if I were to attempt it, I'd do it while running Puppy entirely in RAM (boot from a live CD with puppy pfix=ram  boot option, or, better yet, from a multisession CD or DVD.) Running entirely in RAM means you can try things out without so much risk of borking your hd installation. Once you get your project to work, then you boot from hd and install it. Smile
Ehhh this ansfer will not help me :) - i don;t have problems with instalation/speed of instalation but with enabling sound on window popup :)

George2002

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

Job-Alert

#7 Post by seaside »

I decided to give this a try and develop a general script which can be used for any reason, including Jdownloader.

So here's Job-Alert, for those occasions where you'd like to have a popup with a repeated warning sound when a selected window appears.

Set the following variables in the script-

WINDOWNAME='<--put title of the window sought here-->'
( Apparently for Jdownloader that would be 'Please' )

SOUNDFILE='<---put the /path/soundfile here-->'
( Default is SOUNDFILE='/usr/share/audio/2barks.wav' )

Some Puppies have "xdotool", which is required, but if you don't, it can be found here in Pastelist http://208.109.22.214/puppy/viewtopic.p ... cabb7e7895.

Start the Job-Alert script before launching any programs that might produce a window name of interest.

Job-Alert will poll every 2 seconds for a window with WINDOWNAME in it. When it finds one, it pops a Job-Alert window and starts a repeating sound every 6 seconds until the user stops it.

One extremely handy use is to run this script when away from home as a deterrent to burglars. :D :D

Cheers,
s


Code: Select all

#!/bin/sh 

# Loop polls for window title in WINDOWNAME
# If a window with WINDOWNAME is found, a Job Alert popup 
# window occurs and SOUNDFILE is played every 6 seconds until 
# the Job Alert window is closed.
# Requires: xdotool

### set WINDOWNAME to title of window and SOUNDFILE to /path/soundfile
      

    WINDOWNAME='<--put title of the window sought here-->'
    SOUNDFILE='/usr/share/audio/2barks.wav'
    
    while : : ; do
    ID=`xdotool search $WINDOWNAME | head -1`
    [ "$ID" != "" ] && break
    sleep 2
    done
        
    while : : ; do
        aplay $SOUNDFILE $SOUNDFILE
        sleep 6
    done &
    SPID=$!
    
Xdialog --title "Job Alert" --wrap \
--yes "Press YES/NO, ENTER or ESC to stop sound and Exit" 10 30

kill $SPID
  
exit    

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

#8 Post by technosaurus »

I wonder why you chose to have the sound continue until the processed finished instead of just once afterward
__something__ like this using pidof (busybox) instead of xdotool

Code: Select all

PROGRAMS="program1 program2"
PID=NONE

while $PID != "" do
PID=`for x in $PROGRAMS; do pidof $x; done;`
sleep 2
done

minimp3 /usr/share/audio/actioncomplete.mp3 #or use busybox beep
Can't test at the moment, so it may not work.
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].

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

#9 Post by seaside »

technosaurus,

Apparently, in the case of jdownloader, there is a window that appears asking for captcha input and since supposedly this happens when the user is away from their PC, a continuing alert is desirable until turned off.

Not sure about looking for PID, since it may not be known in this case.

Regards,
s

george2002
Posts: 22
Joined: Mon 20 Sep 2010, 19:08

#10 Post by george2002 »

Hello there and thanks for all solutions and suggestions :) but my buddy from work wroted for me this code:

Code: Select all

#    title_window
#    Copyright (C) 2010  Rafal Pogorzelec (mail:http://www.google.com/recaptcha/mailhide/d?k=01we46RSAUuqHSIbxuEMpsSQ==&c=SGoWxLS_x56S5_ScSXPXwCtmTBN5-ln181pkuq2_xpg=)
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

import subprocess,re

if __name__ == '__main__':
    xprop = subprocess.Popen(('xprop', '-root', '-spy'),stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    while True:
        line = xprop.stdout.readline()
        if not line:
            break
        if re.match('_NET_ACTIVE_WINDOW', line):
            try:
                id = re.split(' ', line)[4]
                xwininfo = subprocess.Popen(('xwininfo', '-id', id),stdout=subprocess.PIPE, stderr=subprocess.PIPE)
                while True:
                    line = xwininfo.stdout.readline()
                    if not line:
                        break
                    if re.match('xwininfo', line):
                        m = re.compile('".*"').search(line)
                        if m:
                            title = m.group()
                            print title
                            if re.search('', title):                            
                                play = subprocess.Popen(('aplay','sound/sound.wav'),stdout=subprocess.PIPE, stderr=subprocess.PIPE)
                        
            except IndexError:
                pass
             
and i must say it works awesome :)
Its writed in python language and for working python 2.6 must be installed - pet file of python 2.6 can be found here:http://dotpups.de/puppy4/dotpups/Progra ... 4-i386.pet
Small description/howto:
In attached file there is 2 catalogs:
license - GPL license
tw - in that catalog there is python script that plays sound when wanted window popups and catalog with sound file (default - sound.wav, i added 2 more sounds from windows ;) )
edit line

Code: Select all

if re.search('', title):
for eg jdownloader

Code: Select all

if re.search('Please enter', title):
- for english language version of course ;) eg for Polish it will be:

Code: Select all

if re.search('Prosz wprowadzi', title):
and one file:
start_tw - it's start file for python script - i added this file to my-documents/Startup (autostart catalog in puppy)


PS
Whole popup catalog must be in root catalog :)

PS2
Ups i can't attache file :( it can be found here:http://www.megaupload.com/?d=OQ2WLJX9

PS3
Thx abushcrafter for mail antyspam info :)

Best Regards
George2002
Last edited by george2002 on Wed 06 Oct 2010, 17:06, edited 1 time in total.

User avatar
abushcrafter
Posts: 1418
Joined: Fri 30 Oct 2009, 16:57
Location: England
Contact:

#11 Post by abushcrafter »

@george2002 Thanks to you you buddy now has spam. Replace the email with this URL "http://www.google.com/recaptcha/mailhid ... pkuq2_xpg=" to protect it. reCAPTCHA: Stop Spam, Read Books
[url=http://www.adobe.com/flashplatform/]adobe flash is rubbish![/url]
My Quote:"Humans are stupid, though some are clever but stupid." http://www.dependent.de/media/audio/mp3/System_Syn_Heres_to_You.zip http://www.systemsyn.com/

george2002
Posts: 22
Joined: Mon 20 Sep 2010, 19:08

#12 Post by george2002 »

Hello there again :)
I uploaded here:http://www.megaupload.com/?d=500C3JBQ new version of script.
My buddy added very cool feature:
Now sound is played in loop with additional delay between played sound as long as window appears, if window disappears then sound stops playing and waiting for next appear of window


Best Regards
George2002

Post Reply