First time trying to struggle with objects . . .
I'm trying to make this script open processes or files and check PID, when one file is closed, script must take it into account.
When none left, script closes.
This , will open files and check if they are opened, until there is no more, then close.
PBM:When closing them, script only "see" them closing if starting from the last opened, ie:
---------
open "01.txt", then "02.txt", "abc.exe", and "03.txt"
"See" them closing only if first to be closed is last opened: "03.txt", then any one will do.
If an other one is closed, it correct the opened files number only when they're all closed.
---------
First I tried with process, WaitClose, but if I remember correctly, the script is not responding anymore to add others files to check until the file is closed and the WaitClose command finished. It has to be #SingleInstance Off to open others individual instances for each opened files, but only works when the first instance is "unlocked".
WinWait is not what I need, as I check for PID.
Although the script above is working, I need to continue as it is not the solution I need, so I decided to make a continuation thread here:
2/3 How to check multiple processes?
---------
Update - April 2 2017: Working code with a hotkey from the post below:
Code: Select all
!a::
FileSelectFile, OutputVar
Run, %OutputVar%,,,OutputVarPID
if !ProcOnDuty
ProcOnDuty:=Array()
ProcOnDuty.insert(OutputVarPID)
OutputVarPID=
MaxIndex := ProcOnDuty.MaxIndex()
SetTimer, ReCheck
Return
ReCheck:
For index, value in ProcOnDuty
{
Process, Exist, %value%
{
if !errorlevel
{
ProcOnDuty.Remove(index)
MaxIndex := ProcOnDuty.MaxIndex()
If (MaxIndex>0)
MsgBox % "Value: " value " MaxIndex: " MaxIndex " ProcOnDuty.MaxIndex(): " ProcOnDuty.MaxIndex()
; Do whatever you want to do here if you need it
Else
{
SetTimer, ReCheck, Off
;MsgBox,no more exec on duty MaxIndex: %MaxIndex%
; Do whatever you want to do here if you need it
ExitApp
}
}
}
}
return
return
Code: Select all
#NoEnv
#SingleInstance off
;#NoTrayIcon
#Persistent
SendMode Input
DetectHiddenWindows, On
Create_files_and_shortcuts()
return
Create_files_and_shortcuts() {
global
ShortcutArg=%1%
if (!ShortcutArg)
ShortcutArg=%1%
File1=%A_ScriptDir%\12345.txt
Shortcut1=%A_ScriptDir%\12345.txt.lnk
File2=%A_ScriptDir%\678910.txt
Shortcut2=%A_ScriptDir%\678910.txt.lnk
File3=%A_ScriptDir%\1a2b3c.txt
Shortcut3=%A_ScriptDir%\1a2b3c.txt.lnk
if (ShortcutArg || MaxIndex>0) {
GoSub, OpenFiles
} else {
if (FileExist(File1)) {
} else {
;------ 1- Files & shortcut creation - Start - ------
Msgbox,
(
This script will create 3 empty txt files and their modified shortcuts.
When opening them by double clicking on shortcuts, the script is supposed to check opened Process ID (PID).
According to your action on closing or reopening the files via the shortcuts the script will increase and decrease the number of opened files.
And finally the script close when the 3 files will be closed.
)
FileAppend,, %File1%
}
if (FileExist(Shortcut1)) {
} else {
FileCreateShortcut, %A_AhkPath%, %Shortcut1% , %A_ScriptDir%, "%A_ScriptFullPath%" "%A_ScriptDir%\12345.txt", Modified 12345.txt Shortcut
}
if (FileExist(File2)) {
} else {
FileAppend,, %File2%
}
if (FileExist(Shortcut2)) {
} else {
FileCreateShortcut, %A_AhkPath%, %Shortcut2% , %A_ScriptDir%, "%A_ScriptFullPath%" "%A_ScriptDir%\678910.txt", Modified 678910.txt Shortcut
}
if (FileExist(File3)) {
} else {
FileAppend,, %File3%
}
if (FileExist(Shortcut3)) {
} else {
FileCreateShortcut, %A_AhkPath%, %Shortcut3% , %A_ScriptDir%, "%A_ScriptFullPath%" "%A_ScriptDir%\1a2b3c.txt", Modified 1a2b3c.txt Shortcut
}
if (File1 || File2 || File3 || Shortcut1 || Shortcut2 || Shortcut3) {
} else {
}
ExitApp
}
return
}
;------ 1- Files & shortcut creation - End - ------
;------ 2- Double click on Shortcut to open files - Start - ------
OpenFiles:
if (ShortcutArg= File1 || ShortcutArg= File2 || ShortcutArg=File3) {
RunWait, %ShortcutArg%,,, OutputVarPID
ExitApp
}
return
;------ 2- Double click on Shortcut to open files - End - ------