Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Making your machine "beep" when a do-file fails

    Hi, all -
    This a very simple question. When I write a do-file, I often make my computer sound with a "beep," using Keith Kranker's nice package for Windows machines. I've found this great for long projects, since I can read or do other tasks until I hear the timer in my do-file.

    However, I'd like my computer to make a beep or some other warning sound when a do-file fails to complete either due to a coding error, or for another reason. Is there any way to include this using some simple syntax?

    Thanks!
    - Nate
    Nathan E. Fosse, PhD
    [email protected]

  • #2
    I am not sure I understand the question, but could you not simply write a do-file that calls other do-files like

    Code:
    capture noisily do my_first_dofile
    if (_rc) {
        beep
    }
    capture noisily do my_second_dofile
    if (_rc) {
        beep
    }
    ...
    Best
    Daniel

    [Edit]
    Oops, forgot to mention that in the above beep is

    Code:
    beep from http://kk-adofiles.googlecode.com/hg
        beep. / Send a "beep" to your computer speakers (Windows only) / / By
        Keith Kranker / $ / Program by Keith Kranker
    [/Edit]
    Last edited by daniel klein; 23 Sep 2015, 13:45.

    Comment


    • #3
      Hi, Daniel -
      Yes, you got what I was trying to say that will work if I'm running other do-files. Yes; I use Kraner's beep syntax.
      Cheers,
      - Nate
      Nathan E. Fosse, PhD
      [email protected]

      Comment


      • #4
        Oddly enough, Stata has an official beep command.

        Code:
         
        . which beep
        built-in command:  beep

        Comment


        • #5
          Thanks, Nick! I actually didn't know that, so why the Keith Kranker ado to invoke shell and use their beep.

          Here's the deal: I'm not going to make a huge complaint, as I love this beep. It's great for letting long do-files and dependencies run. I only wish one could tweak the beep sound itself. On my machine (Windows 7) it's a bit jarring. Also, wouldn't it be nice to have a different beep for say, a return code as opposed to completion of a do-file, as well as completion of dependency or included do-file? I was trying to hack Kranker's shell command to invoke different beeps and bloops to that effect but gave up.

          Perhaps those more familiar with shell may provide some code to permit a wider pallette of beeps? It's been years of hearing the same tintinabulation of the beep, beep beep.

          (As an aside, I know this is feasible; R, for example, although verboten in some fora, permits beeps that are overly specific, down to the hertz).

          In brief, is there anyone in StataList with knowledge of altering the beep function to premit a wider array of sounds, ostensibly invoking shell?

          Much appreciated!
          Nathan E. Fosse, PhD
          [email protected]

          Comment


          • #6
            If you place a .wav file in the same folder as your .ado file, you can define a new program as follows:
            Code:
            program tada 
            
                qui findfile yourfile.wav
                global S_SHELL "PowerShell.exe -WindowStyle Minimized"
                
                
                ! (New-Object Media.SoundPlayer "`r(fn)'").PlaySync();
            
                end

            Comment

            Working...
            X