how to modify this script (List View of running scripts)?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Guest10
Posts: 578
Joined: 01 Oct 2013, 02:50

how to modify this script (List View of running scripts)?

15 Jan 2014, 18:10

this script by Wicked gives a List View of currently running scripts. i can adjust the left column (Name) by a double-click on the "divider | " to the right of Name. how can i modify the code to accomplish the following 2?:
1. Left Column (Name) WIDTH is automatically adjusted at the opening without double clicking "divider | " each time.
2. How to print a list of running scripts so that i can save it to a text file?

Code: Select all

; http://www.autohotkey.com/board/topic/95550-how-to-get-a-list-of-autohotkey-scripts-running/
; http://www.xp-waste.com/post23929.html#p23929

#Persistent
#SingleInstance FORCE
#NoEnv
SendMode, Input
SetWorkingDir, %A_ScriptDir%

_Process:=Object()

/*
Gui, 1: Margin, 5, 5
Gui, 1: Add, ListView, w310 h200 AltSubmit NoSortHdr vListView, Name|PID
Gui, 1: Add, Button, x+-310 y+5 w100 h25, Refresh
Gui, 1: Add, Button, x+5 y+-25 w100 h25, Reload
Gui, 1: Add, Button, x+5 y+-25 w100 h25, Close
*/

Gui, 1: Margin, 5, 5
Gui, 1: Add, ListView, w175 h300 AltSubmit NoSortHdr vListView, Name|PID
Gui, 1: Add, Button, x+-175 y+5 w50 h25, Refresh
Gui, 1: Add, Button, x+12.5 y+-25 w50 h25, Reload
Gui, 1: Add, Button, x+12.5 y+-25 w50 h25, Close

ButtonRefresh:
    Gui, 1: Show
    LV_Delete()
    _Processes:=0
    _Process.Remove(0,_Process.MaxIndex())
    GuiControl, -ReDraw, ListView
    For Process in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Process where Name='AutoHotkey.exe'")
    {
        If(Process.ExecutablePath==A_AHKPath)
        {
            _Processes++
            _Process[_Processes]:=[Extract_Script_Name_From_CommandLine(Process.CommandLine) 
				  ,Extract_Script_Path_From_CommandLine(Process.CommandLine),Process.ProcessId]
            LV_Add("", _Process[_Processes,1],Process.ProcessId)
        }
    }
    GuiControl, +ReDraw, ListView
return


ButtonReload:
    If !LV_GetNext(0)
        Return
    _ScriptDIR:=_Process[LV_GetNext(0),2]
    Run, "%A_AHKPath%" /restart "%_ScriptDIR%"
    Sleep (500)
    GoSub, ButtonRefresh
Return

ButtonClose:
    If !LV_GetNext(0)
        Return
    Process,Close, % _Process[LV_GetNext(0),3]
    Sleep (500)
    GoSub, ButtonRefresh
Return

Extract_Script_Name_From_CommandLine(P) {
    StringSplit,R,P,"
    SplitPath,R4,F
    Return F
}

Extract_Script_Path_From_CommandLine(P) {
    StringSplit,R,P,"
    Return R4
}

^Esc::ExitApp
Therobotmd
Posts: 7
Joined: 06 Jan 2014, 03:50

Re: how to modify this script (List View of running scripts)

16 Jan 2014, 01:11

See LV_Modify() for solution #1 and LV_GetText() for solution #2. Here's the modified script.

Code: Select all

; http://www.autohotkey.com/board/topic/95550-how-to-get-a-list-of-autohotkey-scripts-running/
; http://www.xp-waste.com/post23929.html#p23929

#Persistent
#SingleInstance FORCE
#NoEnv
SendMode, Input
SetWorkingDir, %A_ScriptDir%

_Process:=Object()

/*
Gui, 1: Margin, 5, 5
Gui, 1: Add, ListView, w310 h200 AltSubmit NoSortHdr vListView, Name|PID
Gui, 1: Add, Button, x+-310 y+5 w100 h25, Refresh
Gui, 1: Add, Button, x+5 y+-25 w100 h25, Reload
Gui, 1: Add, Button, x+5 y+-25 w100 h25, Close
*/

Gui, 1: Margin, 5, 5
Gui, 1: Add, ListView, w220 h300 AltSubmit NoSortHdr vListView, Name|PID
Gui, 1: Add, Button, x+-220 y+5 w50 h25, Refresh
Gui, 1: Add, Button, x+7 y+-25 w50 h25, Reload
Gui, 1: Add, Button, x+7 y+-25 w50 h25, Close
Gui, 1: Add, Button, x+7 y+-25 w50 h25, Save
LV_ModifyCol()

ButtonRefresh:
   Gui, 1: Show
    LV_Delete()
    _Processes:=0
    _Process.Remove(0,_Process.MaxIndex())
    GuiControl, -ReDraw, ListView
    For Process in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Process where Name='AutoHotkey.exe'")
    {
        If(Process.ExecutablePath==A_AHKPath)
        {
            _Processes++
            _Process[_Processes]:=[Extract_Script_Name_From_CommandLine(Process.CommandLine) 
                  ,Extract_Script_Path_From_CommandLine(Process.CommandLine),Process.ProcessId]
            LV_Add("", _Process[_Processes,1],Process.ProcessId)
        }
    }
	LV_ModifyCol()
    GuiControl, +ReDraw, ListView
return

ButtonSave:
t:=""
Loop % LV_GetCount()
{
	LV_GetText(OutputVar1,A_Index,1)
	LV_GetText(OutputVar2,A_Index,2)
	t.= OutputVar1 A_Space OutputVar2 "`n"
}
MsgBox % "Would you like to save this file? `n`n" t
IfMsgBox, Yes
	FileAppend, t, test.txt
return

ButtonReload:
   If !LV_GetNext(0)
        Return
    _ScriptDIR:=_Process[LV_GetNext(0),2]
    Run, "%A_AHKPath%" /restart "%_ScriptDIR%"
    Sleep (500)
    GoSub, ButtonRefresh
Return

ButtonClose:
   If !LV_GetNext(0)
        Return
    Process,Close, % _Process[LV_GetNext(0),3]
    Sleep (500)
    GoSub, ButtonRefresh
Return

Extract_Script_Name_From_CommandLine(P) {
    StringSplit,R,P,"
    SplitPath,R4,F
    Return F
}

Extract_Script_Path_From_CommandLine(P) {
    StringSplit,R,P,"
    Return R4
}

^Esc::ExitApp
Guest10
Posts: 578
Joined: 01 Oct 2013, 02:50

Re: how to modify this script (List View of running scripts)

16 Jan 2014, 08:28

fanetastik! the only change i made was as follows: FileAppend, %t%, test.txt :D
Therobotmd wrote:See LV_Modify() for solution #1 and LV_GetText() for solution #2. Here's the modified script.

Code: Select all

; http://www.autohotkey.com/board/topic/95550-how-to-get-a-list-of-autohotkey-scripts-running/
; http://www.xp-waste.com/post23929.html#p23929

#Persistent
#SingleInstance FORCE
#NoEnv
SendMode, Input
SetWorkingDir, %A_ScriptDir%

_Process:=Object()

/*
Gui, 1: Margin, 5, 5
Gui, 1: Add, ListView, w310 h200 AltSubmit NoSortHdr vListView, Name|PID
Gui, 1: Add, Button, x+-310 y+5 w100 h25, Refresh
Gui, 1: Add, Button, x+5 y+-25 w100 h25, Reload
Gui, 1: Add, Button, x+5 y+-25 w100 h25, Close
*/

Gui, 1: Margin, 5, 5
Gui, 1: Add, ListView, w220 h300 AltSubmit NoSortHdr vListView, Name|PID
Gui, 1: Add, Button, x+-220 y+5 w50 h25, Refresh
Gui, 1: Add, Button, x+7 y+-25 w50 h25, Reload
Gui, 1: Add, Button, x+7 y+-25 w50 h25, Close
Gui, 1: Add, Button, x+7 y+-25 w50 h25, Save
LV_ModifyCol()

ButtonRefresh:
   Gui, 1: Show
    LV_Delete()
    _Processes:=0
    _Process.Remove(0,_Process.MaxIndex())
    GuiControl, -ReDraw, ListView
    For Process in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Process where Name='AutoHotkey.exe'")
    {
        If(Process.ExecutablePath==A_AHKPath)
        {
            _Processes++
            _Process[_Processes]:=[Extract_Script_Name_From_CommandLine(Process.CommandLine) 
                  ,Extract_Script_Path_From_CommandLine(Process.CommandLine),Process.ProcessId]
            LV_Add("", _Process[_Processes,1],Process.ProcessId)
        }
    }
	LV_ModifyCol()
    GuiControl, +ReDraw, ListView
return

ButtonSave:
t:=""
Loop % LV_GetCount()
{
	LV_GetText(OutputVar1,A_Index,1)
	LV_GetText(OutputVar2,A_Index,2)
	t.= OutputVar1 A_Space OutputVar2 "`n"
}
MsgBox % "Would you like to save this file? `n`n" t
IfMsgBox, Yes
	FileAppend, t, test.txt
return

ButtonReload:
   If !LV_GetNext(0)
        Return
    _ScriptDIR:=_Process[LV_GetNext(0),2]
    Run, "%A_AHKPath%" /restart "%_ScriptDIR%"
    Sleep (500)
    GoSub, ButtonRefresh
Return

ButtonClose:
   If !LV_GetNext(0)
        Return
    Process,Close, % _Process[LV_GetNext(0),3]
    Sleep (500)
    GoSub, ButtonRefresh
Return

Extract_Script_Name_From_CommandLine(P) {
    StringSplit,R,P,"
    SplitPath,R4,F
    Return F
}

Extract_Script_Path_From_CommandLine(P) {
    StringSplit,R,P,"
    Return R4
}

^Esc::ExitApp

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Araphen, Google [Bot], haomingchen1998, Peiya, rubeusmalfoy and 101 guests