; Version 0.2 #SingleInstance Force /* 1. load and saving from inifile DONE 2. gui with list of crons DONE 3. add/edit/delete DONE 4. statuswindow (next n jobs) 5. traytooltip IN PROGRESS 6. menu: start/stop/pause 7. logging IN PROGRESS */ ; ; Add new default menu item allowing double clicking to open main GUI ; Menu, Tray, Add, Show cron jobs, ShowCronJobs Menu, Tray, Default, Show cron jobs ; ; Establish GUI specific parameters ; If FileExist("cron.ini") { IniRead,ShowAtStartup,cron.ini,Settings,ShowAtStartup,0 IniRead,cron_logfilename,cron.ini,Settings,LogFileName,%A_Space% } Else ShowAtStartup = 1 ; ; Load cron from ini-file (cron.ini) ; cron_load() ; ; Show main GUI ; If ShowAtStartup gosub ShowCronJobs ; ; End of auto-execute section ; Return ; ; reload and exit ; ; f12::reload ; +f12::exitapp ; ; MAIN GUI ; ; Optionally started when script is executed (or with F11) ; f11:: ShowCronJobs: ; ; Create GUI 2 ; Gui, 2:Default Gui, 2:Destroy Gui, 2:Add, ListView,r5 w520 -Multi NoSortHdr ReadOnly AltSubmit gLV,Mins|Hours|Days|Months|Days in week|Target|Parameters|Working dir ; Set column widths Loop 5 LV_ModifyCol(A_Index, 60) LV_ModifyCol(6, 200) LV_ModifyCol(7, 000) LV_ModifyCol(8, 000) ; Fill the grid with cron entries Loop %cron_records% { cron_ := cron_table%a_index% stringsplit,cron_,cron_,| ; cron1 min ; cron2 hour ; cron3 day ; cron4 month ; cron5 dayofweek target := cron_target%a_index% parameters := cron_parameters%a_index% workingdir := cron_workingdir%a_index% LV_ADD("",cron_1,cron_2,cron_3,cron_4,cron_5,target,parameters,workingdir) } ; Add extra fields Gui, 2:Add,Text,x010 y110 ,Parameters Gui, 2:Add,Edit,xp+100 yp-005 W400 vParameters gParametersChanged, Gui, 2:Add,Text,xp-100 yp+030 ,Workingdir Gui, 2:Add,Edit,xp+100 yp-005 W400 vWorkingDir gWorkingDirChanged, Gui, 2:Add,Text,xp-100 yp+30 ,Show at startup Gui, 2:Add,CheckBox,xp+100 vShowAtStartup , ; Add buttons Gui, 2:Add,Button,x010 W80 y+12,Add Gui, 2:Add,Button,xp+100 W80,Edit Gui, 2:Add,Button,xp+100 W80,Delete Gui, 2:Add,Button,xp+200 W80 Default,OK Gui, 2:Show ; Load variables GuiControl,,ShowAtStartup,%ShowAtStartup% Return ; ; Handling of listview single click to fill fields ; LV: If A_GuiEvent = Normal { row := A_EventInfo par := cron_parameters%row% wdir := cron_workingdir%row% GuiControl,,Parameters,%par% GuiControl,,WorkingDir,%wdir% } Return ; ParametersChanged: Gui,Submit,NoHide row := LV_GETNEXT(0,"F") cron_parameters%row% := Parameters Return WorkingDirChanged: Gui,Submit,NoHide row := LV_GETNEXT(0,"F") cron_workingdir%row% := WorkingDir Return ; ; Handling of buttons ; 2ButtonAdd: Mode=Add Gosub,2AddEdit Return 2ButtonEdit: Mode=Edit Gosub,2AddEdit Return 2ButtonDelete: Gosub,2Delete Return ; ; NOTE OK saves and falls through and destroys the GUI ; 2ButtonOK: Gui,Submit IniWrite,%ShowAtStartup%,cron.ini,Settings,ShowAtStartup cron_save() 2GuiEscape: Gui,Destroy Return ; ; Adding and editing of entries in the cron table ; 2AddEdit: Gui, 2:Submit,NoHide ; Get focused row and values depending on the mode of operation If Mode = Edit { row := LV_GETNEXT(0,"F") cron_ := cron_table%row% target := cron_target%row% parameters := cron_parameters%row% workingdir := cron_workingdir%row% } Else { cron_ := "*|*|*|*|*" target := "" parameters := "" workingdir := "" } StringSplit,cron_,cron_,| if (Mode = "Add" OR row) { ; ; Create GUI 4 for adding and editing a cron entry ; Gui, 4:Destroy Gui, 4:Add,Text,,%Mode% Cron entry Gui, 4:Add,Text, ,Minutes Gui, 4:Add,Edit,xp+100 yp+000 W200 vMinutes ,%cron_1% Gui, 4:Add,Text,xp-100 yp+030 ,Hours Gui, 4:Add,Edit,xp+100 yp+000 W200 vHours ,%cron_2% Gui, 4:Add,Text,xp-100 yp+030 ,Days Gui, 4:Add,Edit,xp+100 yp+000 W200 vDays ,%cron_3% Gui, 4:Add,Text,xp-100 yp+030 ,Months Gui, 4:Add,Edit,xp+100 yp+000 W200 vMonths ,%cron_4% Gui, 4:Add,Text,xp-100 yp+030 ,Days in week Gui, 4:Add,Edit,xp+100 yp+000 W200 vWDays ,%cron_5% Gui, 4:Add,Text,xp-100 yp+030 ,Target Gui, 4:Add,Edit,xp+100 yp+000 W400 vTarget ,%target% Gui, 4:Add,Text,xp-100 yp+030 ,Parameters Gui, 4:Add,Edit,xp+100 yp+000 W400 vParameters,%parameters% Gui, 4:Add,Text,xp-100 yp+030 ,Workingdir Gui, 4:Add,Edit,xp+100 yp+000 W400 vWorkingDir,%workingdir% Gui, 4:Add,Button, W80,Cancel Gui, 4:Add,Button,xp100 W80 Default,OK Gui, 4:Show } Return ; ; Handling of buttons ; 4GuiEscape: 4ButtonCancel: Gui, 4:Destroy Return 4ButtonOK: Gui, 4:Submit,NoHide ; Validate values If Not Target { MsgBox Target must be specified Return } ; use a function provided by Skan to find Target in path (among other) If !FileExist(Target) Target := WhereIs(Target) If Not Target { MsgBox Target not found Return } If (workingdir AND !FileExist(workingdir)) { MsgBox Working directory not found Return } ; ; Insert or update the entered values ; If Mode=Add { cron_insert(Minutes,Hours,Days,Months,WDays,Target,Parameters,WorkingDir) Gui,2:Default LV_ADD("Select",Minutes,Hours,Days,Months,WDays,Target,Parameters,WorkingDir) } Else { cron_table%row% := Minutes . "|" . Hours . "|" . Days . "|" . Months . "|" . WDays cron_target%row% := Target cron_parameters%row% := Parameters cron_workingdir%row% := WorkingDir cron_restart() Gui,2:Default LV_Modify(row,"Select",Minutes,Hours,Days,Months,WDays,Target,Parameters,WorkingDir) } Gui, 4:Destroy Return ; ; Deleting an entry in the cron table ; 2Delete: Gui, 2:Submit,NoHide row := LV_GETNEXT(0,"F") if (row) { ; confirm the deleting LV_GETTEXT(Target,row,6) Gui, 3:Destroy Gui, 3:Add,Text,,Delete Cron for %Target% Gui, 3:Add,Button, W80,Cancel Gui, 3:Add,Button,xp100 W80 Default,OK Gui, 3:Show } Return ; ; Handling of buttons ; 3GuiEscape: 3ButtonCancel: Gui, 3:Destroy Return 3ButtonOK: if (row) { Gui, 2:Default LV_DELETE(row) ; move records up move := cron_records-row loop %move% { tmp := row+1 cron_table%row% := cron_table%tmp% cron_target%row% := cron_target%tmp% cron_parameters%row% := cron_parameters%tmp% cron_workingdir%row% := cron_workingdir%tmp% row++ } ; and decrease counter cron_records-- } Gui, 3:Destroy Return ; ; a little helper from Skan ; http://www.autohotkey.com/forum/viewtopic.php?t=22573&postdays=0&postorder=asc&start=15 ; locate file in known places WhereIs( File ) { SplitPath, A_AhkPath,, A_AhkDir EnvGet, Dos, Path sPath=%A_WorkingDir%;%A_ScriptDir%;%A_AhkDir%;%A_AhkDir%\Lib;%A_MyDocuments%\Lib;%Dos% Loop, Parse, sPath, `; IfNotEqual, A_LoopField,, IfExist, %A_LoopField%\%File% Return, RegExReplace( A_LoopField "\" File, "\\\\", "\" ) RegRead, AppPath, HKLM, SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\%File% IfExist, %AppPath%, Return, AppPath }