InSync - Script mit zugewiesener Anwendung starten und beenden

Veröffentliche deine funktionierenden Skripte und Funktionen

Moderator: jNizM

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

InSync - Script mit zugewiesener Anwendung starten und beenden

23 May 2022, 08:15

Basierend auf einer Anfrage von :arrow: hier ein kleines script, dessen Aufgabe es ist, Dateien (hier AHK scripts) in Echtzeit mit einer zugewiesenen Anwendung zu starten, sowie zu beenden.

Code: Select all

#SingleInstance, Force
#Persistent
SetWorkingDir, A_ScriptDir

global apps := {"notepad.exe":0                       ; apps-array <application>:<script status>
               ,"mspaint.exe":0
               ,"calculator.exe":0}

SetTimer, runApp, 500                                 ; check every 500ms..
Return

runApp:
   for proc, scr in apps                              ; ..for existing apps that are listed in the array
      proc(proc)
   Return

proc(app) {
   if FileExist(app)=0 {                              ; check for an associated script for this process
      MsgBox % "Missing " SubStr(app,1,-4) ".ahk !"
      ExitApp
      }
   Process, Exist,% app                               ; let's see if the expected app is processing.
   if (errorlevel != 0) && (apps[app] = 0) {          ; it is - but no associated script is running.
      Run % SubStr(app,1,-4) ".ahk",,, scrID          ; so, let's run the script..
      apps[app] := scrID                              ; ..and update its status within the apps-array.
      }
   if (errorlevel = 0) && (apps[app] != 0) {          ; nope, the app isn't processing anymore, but its associated script is still running
      Process, Close,% apps[app]                      ; therefore let's close the scripts process
      apps[app] := 0                                  ; ..and let's update the scripts 'running' status accordingly!
      }
   }

8-) HTH

Return to “Skripte und Funktionen”

Who is online

Users browsing this forum: No registered users and 3 guests