Ask AI on The Internet
Question: create an autohotkey script when i can drag and drop an app shortcut and constantly monitor if that shortcuts exe is running or not by displaying a green icon if the app is running or red icon if it is not. I should be able to add multiple apps and save the setup. allow me to right click an app in the list and remove it
Absolutely, here's a basic implementation of your request in AutoHotkey v1.1 (the script will work best in v1.1, as v2 syntax differs) with some explanations and simple persistence. This will: - Let you drag and drop shortcuts or EXE files onto the GUI. - Constantly monitor whether the target EXE is running. - Show a green LED icon (?) if it's running, a red LED (?) if it's not. - Allow you to remove items via right-click. - Save and load your app list in an .ini file. You can use Unicode emoji as "icons" for clarity and simplicity, or substitute real icons if desired. **Here's the script:** ```ahk #NoEnv #SingleInstance Force SetBatchLines, -1 List := [] IniFile := A_ScriptDir "\app_monitor.ini" ; Read saved apps If (FileExist(IniFile)) { Loop, Read, %IniFile% { If !InStr(A_LoopReadLine, "=") Continue k := StrSplit(A_LoopReadLine, "=")[1] v := StrSplit(A_LoopReadLine, "=")[2] List.Push({Name: k, Path: v}) } } Gui, Add, ListView, x10 y10 r15 w400 gAppList AltSubmit vLV hwndHLV, App|Status ShowList() Gui, Show, , App Monitor SetTimer, UpdateStatus, 1000 OnMessage(0x233, "WM_DROPFILES") DllCall("Shell32.dll\DragAcceptFiles", "UInt", HLV, "Int", 1) Return ; Functions ShowList() { global List Gui, ListView, LV LV_Delete() For i, app in List { LV_Add("", app.Name, "...") } } ; Update status every second UpdateStatus: global List Gui, ListView, LV Loop % LV_GetCount() { LV_GetText(AppName, A_Index, 1) LV_Modify(A_Index, ,"") ; Clear For idx, app in List { If (app.Name = AppName) { SplitPath, app.Path,,, ext, exe exe := (ext="lnk") ? GetTargetFromLnk(app.Path) : app.Path Process, Exist, % exe status := (ErrorLevel) ? "?":"?" LV_Modify(A_Index,"",app.Name, status) } } } Return AppList: If (A_GuiEvent = "R") { LV_GetText(AppName, A_EventInfo, 1) If (AppName) { If (MsgBox("Remove " AppName "?","Question",4)=6) { For idx, app in List { If (app.Name = AppName) { List.RemoveAt(idx) Break } } ShowList() SaveList() } } } Return GuiDropFiles: WM_DROPFILES(wParam, lParam, msg, hwnd) { global List VarSetCapacity(file, 260*2, 0) loop { DllCall("Shell32.dll\DragQueryFile", "ptr", wParam, "UInt", A_Index-1, "ptr", &file, "UInt", 260) fn := StrGet(&file) if (fn = "") break SplitPath, fn, ShortName, dir, ext, name_no_ext If !(ext="lnk" or ext="exe") Continue If (ext="lnk") { exe := GetTargetFromLnk(fn) If (!exe) Continue SplitPath, exe, ename List.Push({Name:ename, Path:fn}) } else { List.Push({Name:ShortName, Path:fn}) } } ShowList() SaveList() } ; Get target path from shortcut (.lnk) GetTargetFromLnk(fn) { shell := ComObjCreate("WScript.Shell") shlink := shell.CreateShortcut(fn) return shlink.TargetPath } ; Persist list to ini file SaveList() { global List, IniFile FileDelete, %IniFile% For idx, app in List FileAppend, %app.Name%=%app.Path%`n, %IniFile% } ; Utility for right-click message box MsgBox(title, text, type:=0) { Return DllCall("user32\MessageBox", "Ptr",0, "Str", title, "Str", text, "UInt", type) } GuiClose: ExitApp ``` **Instructions:** 1. Save as `AppMonitor.ahk` and run (needs AHK v1.1). 2. Drag & drop app shortcuts (.lnk) or .exe files onto the window. 3. The list is updated in app_monitor.ini for persistence. 4. Status shows ? (green) if the EXE is running, ? (red) if not. 5. Right-click on an app in the list to remove it. **Note:** - This script uses emoji for "icons" (so works anywhere), but you could use .ico files with the ListView if desired. - It uses COM to read shortcut targets, so it will work for .lnk files as well as direct .exe. If you want something more robust or prettier (tray icons, custom images), let me know!
Sure! Below is a basic AutoHotkey (AHK) script that sets up a GUI where you can drag and drop application shortcuts to add them to a monitoring list. The script will display a green or red icon depending on whether each application's `.exe` is currently running. You can also right-click an app in the list to remove it. ```ahk #Persistent #NoEnv SetWorkingDir %A_ScriptDir% SetBatchLines, -1 Gui, +Resize Gui, Add, ListView, x10 y10 w480 h400 +ReadOnly vAppList gAppList, Application|Status Gui, Add, Button, x10 y420 w70 gSaveSetup, Save Gui, Add, Button, x90 y420 w70 gLoadSetup, Load GuiContextMenu: LV_GetText(AppName, A_EventInfo, 1) Menu, RemoveAppMenu, Add, Remove '%AppName%', RemoveApp Menu, RemoveAppMenu, Show return RemoveApp: LV_Delete(A_EventInfo) return GuiDropFiles: Loop, Parse, A_GuiEvent, `n { IfExist %A_LoopField% { SplitPath, A_LoopField, OutFileName, OutDir, OutExt, OutName, OutDrive AddApp(OutName, OutDir) } } return AddApp(AppName, AppPath) { LV_Add("", AppName, "----") LV_ModifyCol() } SaveSetup: FileDelete, Apps.ini Loop, Parse, LV_GetCount() { LV_GetText(AppName, A_Index, 1) LV_GetText(Status, A_Index, 2) IniWrite, %LV_GetText(A_Index, 1)%, Apps.ini, Apps, %A_Index% } return LoadSetup: If FileExist("Apps.ini") { LV_Delete() Loop { IniRead, AppName, Apps.ini, Apps, %A_Index% if (AppName = "ERROR") break AddApp(AppName, "") } } return SetTimer, CheckAppStatus, 5000 return CheckAppStatus: Loop, Parse, LV_GetCount() { LV_GetText(AppName, A_Index, 1) if (ProcessRunning(AppName)) { LV_Modify(A_Index, "Col2", "Green") } else { LV_Modify(A_Index, "Col2", "Red") } } return ProcessRunning(Name) { Process, Exist, %Name%.exe return !!ErrorLevel } GuiClose: ExitApp return AppList: if (A_GuiEvent = "R") { LV_GetText(AppName, A_EventInfo) Menu, RemoveAppMenu, Show } return ``` ### Instructions: 1. **Add Applications:** - Drag and drop application shortcuts into the main GUI window. The applications will be added to the list. 2. **Monitor Applications:** - The script checks every 5 seconds if the applications are running or not. - A green icon indicates that the application is running, and a red icon indicates that it is not. 3. **Save/Load Setup:** - Click the "Save" button to save the current setup to an `Apps.ini` file. - Click the "Load" button to load the applications from the `Apps.ini` file. 4. **Remove Applications:** - Right-click on an application in the list and select "Remove" to remove it from the monitoring list. Make sure you have `autohotkey` installed to use this script. Save the content into a file with the `.ahk` extension and run it using AutoHotkey. This will provide you with a basic interface to monitor your applications.
Think your answer is better than the AI's? Post it below.
Other Most Relevant Posts:
Question Tags
If you want your question answered by an AI, click here.






Post your own comment or use AI: