Hi,
ich hatte mich schon mal versucht an AutoIt vor so circa einem Jahr. Und hatte es aber seitdem ruhen lassen.
Inzwischen arbeite ich oft im sogenannten Home-Office und ich hab immer mal wieder mit der Prokrastination zu kämpfen. Und dann gibt es Abends ärger von der besseren Hälfte, dass man immer noch am arbeiten ist weil man vorher Sachen aufgeschoben hat.
Ich poste in der n00b-Section weil ich kein Programmierer bin, ich keine Ahnung vom Programmieren habe und ich vielleicht ein bisschen logisches Verständnis habe und somit ein paar Zeilen hin bekommen habe.
Also da ich mich öfter mal am Computer ablenke anstatt produktiv zu arbeiten hab ich mir gedacht, dass mich ein kleines Script unterstützen könnte.
Die Idee:
1. Alles was nicht auf einer Blacklist steht wird geschlossen.
2. Wenn ein Programm im Vordergrund ist was auf einer Whitelist steht, dann schläft das Script bis ein anderes Programm im Vordergrund ist.
3. Lernmodus: Bei alle Programme die das Script noch nicht kennt wird nach gefragt ob auf die Blacklist oder Whitelist.
So weit bin ich bisher gekommen:
Spoiler anzeigen
#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=procrastination.ico
#AutoIt3Wrapper_Outfile=procrastination.exe
#AutoIt3Wrapper_Compression=0
#AutoIt3Wrapper_Res_Language=1033
#AutoIt3Wrapper_Run_Tidy=y
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
#region options
Opt("MustDeclareVars", 1)
AutoItSetOption("TrayIconDebug", 1)
AutoItSetOption("TrayAutoPause", 0)
;~ AutoItSetOption("TrayIconHide", 1)
#endregion options
#region include
#include<File.au3>
#include<Array.au3>
#include<Debug.au3>
#include<Process.au3>
#include<WindowsConstants.au3>
#include<GUIConstantsEx.au3>
#include<EditConstants.au3>
_DebugSetup("debug procrastination", True, 2)
#endregion include
#region variables
Global $aWhitelistTitle
Global $aWhitelistProcess
Global $aBlacklistProcess
Global $aBlacklistTitle
Global $hGUI
Global $input_process
Global $input_title
Global $button_whitelist_process
Global $button_whitelist_title
Global $button_blacklist_process
Global $button_blacklist_title
Global $aGUI
Global $aGUImsg
Global $learn_new
Global $howmanyGUIs
#endregion variables
#region load lists
; whitelist_title to array
Global $sFile1 = @ScriptDir & "\lists\WhitelistTitle" ;WhitelistTitle file one entry per line
_FileReadToArray($sFile1, $aWhitelistTitle)
If @error = 1 Then
MsgBox(4096, "Error", "Error opening file: WhitelistTitle")
Exit
ElseIf @error = 2 Then
MsgBox(4096, "Error", "Corrupted file: WhitelistTitle")
Exit
EndIf
_DebugOut("Whitelist_title2Array_Successful")
Sleep(100)
; whitelist_title to array
Global $sFile2 = @ScriptDir & "\lists\WhitelistProcess" ;WhitelistProcess file one entry per line
_FileReadToArray($sFile2, $aWhitelistProcess)
If @error = 1 Then
MsgBox(4096, "Error", "Error opening file: WhitelistProcess")
Exit
ElseIf @error = 2 Then
MsgBox(4096, "Error", "Corrupted file: WhitelistProcess")
Exit
EndIf
_DebugOut("Whitelist_process2Array_Successful")
Sleep(100)
; blacklist process to array
Global $sFile3 = @ScriptDir & "\lists\BlacklistProcess" ;BlacklistProcess file one entry per line
_FileReadToArray($sFile3, $aBlacklistProcess)
If @error = 1 Then
MsgBox(4096, "Error", "Error opening file: BlacklistProcess")
Exit
ElseIf @error = 2 Then
MsgBox(4096, "Error", "Corrupted file: BlacklistProcess")
Exit
EndIf
_DebugOut("Blacklist_process2Array_Successful")
; blacklist title to array
Global $sFile4 = @ScriptDir & "\lists\BlacklistTitle" ;BlacklistTitle file one entry per line
_FileReadToArray($sFile4, $aBlacklistTitle)
If @error = 1 Then
MsgBox(4096, "Error", "Error opening file: BlacklistTitle")
Exit
ElseIf @error = 2 Then
MsgBox(4096, "Error", "Corrupted file: BlacklistTitle")
Exit
EndIf
_DebugOut("Blacklist_title2Array_Successful")
Sleep(100)
#endregion load lists
#region loop
$learn_new = 1 ; variable that checks if a process or title is already in the arrray
While 1 ; ### loop ####
_DebugOut("StartOfLoop")
Global $wintitle = WinGetTitle("[ACTIVE]") ;title from active window
If $wintitle Then ;check that $wintitle is not empty. Else sleep(250).
Global $winprocess = _ProcessGetName(WinGetProcess($wintitle)) ;process name from active window
For $i = 1 To $aWhitelistProcess[0] ;checks if the process name is on the whitelist
If $winprocess = $aWhitelistProcess[$i] Then
_DebugOut("Whitelist_process_BeforePause")
$learn_new = 0 ; if process name is on whitelist no need to learn new process name
WinWaitNotActive($wintitle) ;if process name is on whitelist script pauses until other window is active.
_DebugOut("Whitelist_process_AfterPause")
ExitLoop
EndIf
Next
If $learn_new Then ;only check other lists if process is not in whitelist_process (hence if the For loop haven't set the $learn_new variable to 0).
For $i = 1 To $aBlacklistProcess[0] ;checks if the process name is on the blacklist
If $winprocess = $aBlacklistProcess[$i] Then
ProcessClose($winprocess) ;close process if on blacklist
$learn_new = 0 ;if name on list no need to learn new process name
_DebugOut("processclose")
ExitLoop
EndIf
Next
Sleep(20)
If $learn_new Then ;only check other lists if process is not in whitelistprocess AND blacklistprocess
For $i = 1 To $aBlacklistTitle[0] ;checks if the window title is on the blacklist
If StringInStr($wintitle, $aBlacklistTitle[$i]) Then
WinSetState($wintitle, "", @SW_HIDE) ;hide window if on blacklist
$learn_new = 0 ;if name on list no need to learn new process name
_DebugOut("winclose")
;~ ExitLoop
EndIf
Next
Sleep(20)
If $learn_new Then ;only check list if process is not in whitelistprocess AND blacklistprocess OR title is not in blacklist
For $i = 1 To $aWhitelistTitle[0] ;checks if the window title is on the whitelist
If StringInStr($wintitle, $aWhitelistTitle[$i]) Then
_DebugOut("Whitelist_title_BeforePause")
WinWaitNotActive($wintitle) ;if process name is on whitelist script pauses until other window is active.
_DebugOut("Whitelist_title_AfterPause")
$learn_new = 0 ;if name on list no need to learn new process name
ExitLoop
EndIf
Next
Sleep(20)
EndIf
EndIf
EndIf
_learnnew()
[/autoit] [autoit][/autoit] [autoit]Else
Sleep(250)
EndIf
$learn_new = 1
_DebugOut("EndOfLoop")
WEnd
#endregion loop
#region functions
Func _learnnew() ;create GUI if new programm
If $learn_new Then
$hGUI = GUICreate("Learning mode - Procrastination Killer", 425, 85, -1, -1, -1, $WS_EX_TOPMOST)
$howmanyGUIs += 1
$input_process = GUICtrlCreateInput($winprocess, 5, 5, 415, 20, BitOR($ES_CENTER, $ES_READONLY))
$input_title = GUICtrlCreateInput($wintitle, 5, 30, 415, 20, $ES_CENTER)
$button_whitelist_process = GUICtrlCreateButton("Whitelist Process", 5, 55, 100, 25)
$button_whitelist_title = GUICtrlCreateButton("Whitelist Title", 110, 55, 100, 25)
$button_blacklist_process = GUICtrlCreateButton("Blacklist Process", 215, 55, 100, 25)
$button_blacklist_title = GUICtrlCreateButton("Blacklist Title", 320, 55, 100, 25)
GUISetState(@SW_SHOW)
If $howmanyGUIs = 1 Then
AdlibRegister("_learnnewgetmsg")
EndIf
EndIf
EndFunc ;==>_learnnew
Func _learnnewgetmsg() ;while GUI active GUIGetMsg
$aGUImsg = GUIGetMsg(1)
If $aGUImsg[0] <> 0 Then
Switch $aGUImsg[0]
Case $button_whitelist_title
_ArrayAdd($aWhitelistTitle, GUICtrlRead($input_title))
GUIDelete($aGUImsg[1])
$howmanyGUIs -= 1
_DebugOut("#whitelisttitle " & $aWhitelistTitle[0])
$aWhitelistTitle[0] += 1
_DebugOut("#whitelisttitle " & $aWhitelistTitle[0])
Global $hFile1 = FileOpen($sFile1, 2)
_FileWriteFromArray($hFile1, $aWhitelistTitle, 1)
FileClose($hFile1)
$howmanyGUIs -= 1
Case $button_whitelist_process
_ArrayAdd($aWhitelistProcess, GUICtrlRead($input_process))
GUIDelete($aGUImsg[1])
$howmanyGUIs -= 1
_DebugOut("#whitelistprocess " & $aWhitelistProcess[0])
$aWhitelistProcess[0] += 1
_DebugOut("#whitelistprocess " & $aWhitelistProcess[0])
Global $hFile2 = FileOpen($sFile2, 2)
_FileWriteFromArray($hFile2, $aWhitelistProcess, 1)
FileClose($hFile2)
$howmanyGUIs -= 1
Case $button_blacklist_process
_ArrayAdd($aBlacklistProcess, GUICtrlRead($input_process))
GUIDelete($aGUImsg[1])
$howmanyGUIs -= 1
_DebugOut("#blacklistprocess " & $aBlacklistProcess[0])
$aBlacklistProcess[0] += 1
_DebugOut("#blacklistprocess " & $aBlacklistProcess[0])
Global $hFile3 = FileOpen($sFile3, 2)
_FileWriteFromArray($hFile3, $aBlacklistProcess, 1)
FileClose($hFile3)
$howmanyGUIs -= 1
Case $button_blacklist_title
_ArrayAdd($aBlacklistTitle, GUICtrlRead($input_title))
GUIDelete($aGUImsg[1])
$howmanyGUIs -= 1
_DebugOut("#blacklisttitle " & $aBlacklistTitle[0])
$aBlacklistTitle[0] += 1
_DebugOut("#blacklisttitle " & $aBlacklistTitle[0])
Global $hFile4 = FileOpen($sFile4, 2)
_FileWriteFromArray($hFile4, $aBlacklistTitle, 1)
FileClose($hFile4)
$howmanyGUIs -= 1
Case $GUI_EVENT_CLOSE
GUIDelete($aGUImsg[1])
$howmanyGUIs -= 1
EndSwitch
If $howmanyGUIs = 0 Then
AdlibUnRegister("_learnnewgetmsg")
EndIf
EndIf
EndFunc ;==>_learnnewgetmsg
#endregion functions
Ich hoffe es macht ein bisschen Sinn und ist auch einiger Maßen verständlich.
Also ich habe in einem Unterverzeichnis "lists" 4 Dateien angelegt (wenn die Dateien leer sind gibt es noch einen Fehler in meinem Script):
WhitelistTitle
WhitelistProcess
BlacklistProcess
BlacklistTitle
Und diese 4 Listen werden am Anfang in jeweils ein Array eingelesen.
Dann im loop wird geschaut ob das gerade aktive Fenster auf der White- oder Blacklist ist.
Und dann wird entweder der Process gekillt oder das Fenter versteckt (Blacklist), bzw. bei der Whitelist wird gewartet bis ein anderes Fenster aktiv ist (WinWaitNotActive).
Probleme im Script:
1. zu hohe CPU Last obwohl Debug mir eigentlich sagt, dass das Script gerade bei WinWaitNotActive pausiert. (Naja die zu hohe CPU Last ist im einstelligen Bereich, aber warum? Ich würde denken wenn da Script gerade bei WinWaitNotActive ist, dann müsste die CPU Last eher so bei 0 sein !?
2. Der loop kann mehrere GUIs öffnen, dann kann man aber nur das zuletzt erstellte GUI schließen.
To-Do Liste:
1. Internetseiten sperren. (Da das Internet doch schon der größte Prokrasinationsfaktor ist eine solche Funktion notwendig.)
1.1. Aber sie setzt man das am Besten um? Weil die bisherige Funktionsweise, dass bei jedem neuen Programm bzw. Fenstertitel eine GUI erstellt wird ist bei Internetseiten nicht gerade praktikabel.
1.2. Am besten wäre ja eine Blacklist die für alle Browser gleichzeitig gilt (FF, IE, chrome).
2. Es schwieriger machen, dass Programm zu beenden. Z.b. Zufallscode generieren und dann muss der eingegeben werden bevor das Programm geschlossen werden kann...
Will jemand mit am Projekt mitwirken?
Ist es überhaupt ein n00b-Projekt? Wahrscheinlich ja, seht ihr ja am Code :pinch: