timer() [UDF]

Veröffentliche deine funktionierenden Skripte und Funktionen

Moderator: jNizM

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

timer() [UDF]

19 Jun 2017, 05:16

Einschlafen hat was, nur das dann die mucke unbeeindruckt weiter fleißig die zimmerpflanzen beschallt is dann doch eher meh.
Anpassen der akustik mit fader() ist eine option, manchmal darfs dann doch etwas mehr sein, ich sags mal so: Anwendungsterminierung!

Wie üblich ohne COM & Cie - AKA noobs best friend.

Code: Select all

#SingleInstance, Force

F1::										  ; press F1 to start the test session
      app := "notepad.exe"                    ; let's select "notepad.exe" for testing
      Run,% app,, Max                         ; start "notepad.exe" so you can see it dying ...                       
      Sleep, 100                              ; yeah, life is beautiful, but ...
      timer(app,0.2,"A")                      ; notepad.exe should die, 0.2min (= 12sec) from now, showing the "A"larm countdown
      Sleep, 1000                             ; powernap before we kill another candidate ...
      timer("calc.exe")                       ; calc.exe should die [after the default period of 0.05min (= 3sec), without showing a countdown]
      ExitApp                                 ; Mission accomplished. Yours sincerely, carnifex.
      }

timer(processName,ttd=0.05,alarm=""){
      Process, Exist,% processName            ; check if process exists, if yes ...
      PID := ErrorLevel                       ; ... let's keep its process ID

      eTime := ttd*60000                      ; calculate time to stop (minutes to milliseconds)
      sTime := A_TickCount                    ; get current time to start with
      i := 0
      
      Loop {
        ToolTip %  msg := (ErrorLevel = 0) ? processName " doesn't exist!" : counter := SubStr((ttd*60)-i,1,-7)  ; create & display tooltip message
        If (counter <= 5) && (alarm = "A")    ; start to alarm if requested, 5 sec prior shutdown
          SoundBeep
        If (A_TickCount - sTime) > eTime-1000 ; time has elapsed, ...
          Break                               ; ... let's do it!
        Sleep, 1000
        i++
        }

      Process, Close,% PID  ; processName     ; Kill the process.
      ToolTip
      }
PS: wer tatsächlich mucke abstellen möchte, lässt diese selbstverständlich vorab mittels fader() kontrolliert runterfaden und dann ... ZACK! :thumbup:
PPS: Frage: welchen vorteil (wenn überhaupt) hätte hier eine SetTimer-routine im vergleich zum Loop :?:

Greetz 8-)
just me
Posts: 9442
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: timer() [UDF]

19 Jun 2017, 06:06

BoBo wrote:PPS: Frage: welchen vorteil (wenn überhaupt) hätte hier eine SetTimer-routine im vergleich zum Loop
Ein Timer blockiert das Skript nicht (wenn er keine Loops, Sleeps, etc. enthält) ;)

Return to “Skripte und Funktionen”

Who is online

Users browsing this forum: No registered users and 13 guests