Cynagen Posted May 22, 2009 Share Posted May 22, 2009 (edited) This was written with the help of CoePSX's MSN Personal Song Message script, available here: http://www.autoitscript.com/forum/index.php?showtopic=43112Also requires my WinProcess script, available here: http://www.autoitscript.com/forum/index.php?showtopic=95328Not sure if anyone else has done this, but a quick search here in the example scripts area didn't turn anything like this up.expandcollapse popup;MSN application based status updater ;Practical use is for gaming ;Credit to Cynagen #include <_MSN.au3> #include <_WinProcess.au3> #include <GUIConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <ComboConstants.au3> #include <Constants.au3> if @Compiled Then $setstatus = 0 if ProcessExists(@ScriptName) <> @AutoItPID then Exit EndIf $version = "BETA v4.5" TraySetToolTip("MSN Application Status Updater " & $version) Opt("TrayOnEventMode",1) Opt("TrayMenuMode",1) ;~ Opt("TrayAutoPause",0) TraySetClick(16) $configshow = TrayCreateItem("Configure application tracking") TrayItemSetOnEvent($configshow,"ConfigureApps") TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE,"ConfigureApps") TrayCreateItem("") $debugshow = TrayCreateItem("Show debug log") TrayItemSetOnEvent($debugshow,"showDebug") $trayexit = TrayCreateItem("Exit") TrayItemSetOnEvent($trayexit,"TrayExit") TraySetState() $debugdata = "" $debugwind = 0 $setstatus = 0 func Debug($dbugin) if $debugwind then msgbox(64,"DEBUG INTERNAL", "DATA PREFLUSH: " & @CRLF & $debugdata, 1) $dbugarr = StringSplit($debugdata,@CRLF,1) $debugdata = "" $d = 1 if $dbugarr[0] = 30 then $d = 2 while $d <= $dbugarr[0] if $dbugarr[$d] <> "" then $debugdata = $debugdata & $dbugarr[$d] & @CRLF $d = $d + 1 WEnd $debugdata = $debugdata & @HOUR & ":" & @MIN & ":" & @SEC & " " & $dbugin & @CRLF ;$out = FileOpen("status.debug",2) ;FileWrite($out,$debugdata) ;FileClose($out) EndFunc func showDebug() MsgBox(64,"DEBUG LOG", $debugdata) EndFunc Func TrayExit() Exit EndFunc Func OnAutoItExit() if $setstatus <> 0 then ChangeMSNMessage(0,False,"") EndFunc TrayTip("MSN Application Status Updater",$version & " Loaded",1) Debug("Application starting") $msnapplist=@ScriptDir & "\msnapplist.ini" if not FileExists($msnapplist) then filewriteline($msnapplist,"[options]" & @CRLF & "sleep=500") ConfigureApps() EndIf Func ConfigureApps() #Region ### START Koda GUI section ### Form= $ConfigWND = GUICreate("MSNStatus Configuration", 345, 417, -1, -1) $Group1 = GUICtrlCreateGroup("Application to add/modify", 8, 0, 329, 57) $AppList = GUICtrlCreateCombo("", 16, 24, 233, 25) $NewApp = GUICtrlCreateButton("New", 249, 24, 40, 20, 0) $DeleteApp = GUICtrlCreateButton("Delete", 288, 24, 43, 20, 0) GUICtrlCreateGroup("", -99, -99, 1, 1) $Group2 = GUICtrlCreateGroup("General Settings", 8, 64, 329, 145) $Label1 = GUICtrlCreateLabel("Prefix", 80, 80, 30, 17, $SS_CENTER) $Label2 = GUICtrlCreateLabel("Suffix", 200, 80, 30, 17, $SS_CENTER) $Label3 = GUICtrlCreateLabel("Music:", 16, 96, 60, 17, $SS_RIGHT) $MusicPrefix = GUICtrlCreateInput("", 80, 94, 121, 21) $MusicSuffix = GUICtrlCreateInput("", 200, 94, 121, 21) $Label4 = GUICtrlCreateLabel("Games:", 16, 120, 60, 17, $SS_RIGHT) $GamePrefix = GUICtrlCreateInput("", 80, 118, 121, 21) $GameSuffix = GUICtrlCreateInput("", 200, 118, 121, 21) $Label5 = GUICtrlCreateLabel("Office:", 16, 144, 60, 17, $SS_RIGHT) $OfficePrefix = GUICtrlCreateInput("", 80, 142, 121, 21) $OfficeSuffix = GUICtrlCreateInput("", 200, 142, 121, 21) $Label6 = GUICtrlCreateLabel("Process checking timer (ms):", 64, 178, 139, 17, $SS_CENTER) $Timer = GUICtrlCreateInput("", 208, 174, 73, 21) GUICtrlCreateGroup("", -99, -99, 1, 1) GUICtrlCreateGroup("", 16, 161, 313, 7) GUICtrlCreateGroup("", -99, -99, 1, 1) $Group3 = GUICtrlCreateGroup("Application Settings", 8, 216, 329, 97) $Label7 = GUICtrlCreateLabel("Name override:", 16, 236, 76, 17, $SS_RIGHT) $NameOverride = GUICtrlCreateInput("", 96, 232, 233, 21) GUICtrlSetTip(-1, "Leaving this blank will use auto-detect, and will show up as {AUTONAME} in the example display.") $Label8 = GUICtrlCreateLabel("Application type:", 16, 258, 82, 17) $TypeG = GUICtrlCreateRadio("Game", 104, 256, 65, 17) $TypeM = GUICtrlCreateRadio("Music", 176, 256, 65, 17) $TypeO = GUICtrlCreateRadio("Office", 248, 256, 65, 17) $Label9 = GUICtrlCreateLabel("Prefix/Suffix override:", 16, 284, 105, 17) $AppPrefix = GUICtrlCreateInput("", 120, 280, 105, 21) $AppSuffix = GUICtrlCreateInput("", 224, 280, 105, 21) GUICtrlCreateGroup("", -99, -99, 1, 1) $Group4 = GUICtrlCreateGroup("Example display", 8, 320, 329, 65) $Label10 = GUICtrlCreateLabel("This is what MSN should display upon activating the application.", 16, 336, 307, 17, $SS_CENTER) $ExampleDisplay = GUICtrlCreateLabel("", 16, 360, 313, 17, BitOR($GUI_SS_DEFAULT_LABEL,$SS_LEFTNOWORDWRAP,$SS_SUNKEN,$SS_NOPREFIX)) GUICtrlCreateGroup("", -99, -99, 1, 1) $OK = GUICtrlCreateButton("OK", 165, 392, 55, 20, 1) $Apply = GUICtrlCreateButton("Apply", 220, 392, 55, 20, 0) $Cancel = GUICtrlCreateButton("Cancel", 275, 392, 55, 20, 0) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### #Region ### Initialize display GUICtrlSetData($Timer,IniRead($msnapplist,"options","sleep",500)) GUICtrlSetData($MusicPrefix,IniRead($msnapplist,"options","prefix0","")) GUICtrlSetData($MusicSuffix,IniRead($msnapplist,"options","suffix0","")) GUICtrlSetData($GamePrefix,IniRead($msnapplist,"options","prefix1","")) GUICtrlSetData($GameSuffix,IniRead($msnapplist,"options","suffix1","")) GUICtrlSetData($OfficePrefix,IniRead($msnapplist,"options","prefix2","")) GUICtrlSetData($OfficeSuffix,IniRead($msnapplist,"options","suffix2","")) $inilist = IniReadSectionNames($msnapplist) if @error then msgbox(0,"Error","Could not read MSN App List for configuration") Exit Else $list="" For $i = 1 to $inilist[0] if $inilist[$i] <> "options" then $list&=$inilist[$i] & "|" Next GUICtrlSetData($AppList,stringtrimright($list,1)) EndIf #EndRegion ### Initialize display dim $lastapp, $showexample=0 While 1 $nMsg = GUIGetMsg() if GUICtrlRead($AppList) <> $lastapp then $nMsg = $AppList $lastapp = GUICtrlRead($AppList) EndIf if $nMsg = $Apply OR $nMsg = $OK then IniWrite($msnapplist,"options","prefix0",GUICtrlRead($MusicPrefix)) IniWrite($msnapplist,"options","suffix0",GUICtrlRead($MusicSuffix)) IniWrite($msnapplist,"options","prefix1",GUICtrlRead($GamePrefix)) IniWrite($msnapplist,"options","suffix1",GUICtrlRead($GameSuffix)) IniWrite($msnapplist,"options","prefix2",GUICtrlRead($OfficePrefix)) IniWrite($msnapplist,"options","suffix2",GUICtrlRead($OfficeSuffix)) IniWrite($msnapplist,"options","sleep",GUICtrlRead($Timer)) $app=GUICtrlRead($AppList) if $app <> "" then if GUICtrlRead($TypeG) = $GUI_CHECKED then IniWrite($msnapplist,$app,"type",1) if GUICtrlRead($TypeM) = $GUI_CHECKED then IniWrite($msnapplist,$app,"type",0) if GUICtrlRead($TypeO) = $GUI_CHECKED then IniWrite($msnapplist,$app,"type",2) if GUICtrlRead($NameOverride) <> "" then IniWrite($msnapplist,$app,"name",GUICtrlRead($NameOverride)) else IniDelete($msnapplist,$app,"name") EndIf if GUICtrlRead($AppPrefix) <> "" Then IniWrite($msnapplist,$app,"prefix",GUICtrlRead($AppPrefix)) Else IniDelete($msnapplist,$app,"prefix") EndIf if GUICtrlRead($AppSuffix) <> "" then IniWrite($msnapplist,$app,"suffix",GUICtrlRead($AppSuffix)) Else IniDelete($msnapplist,$app,"suffix") EndIf EndIf if $nMsg = $OK then GUIDelete($ConfigWND) ExitLoop EndIf $showexample=1 EndIf Switch $nMsg Case $GUI_EVENT_CLOSE GUIDelete($ConfigWND) ExitLoop Case $Cancel GUIDelete($ConfigWND) ExitLoop Case $AppList $app=GUICtrlRead($AppList) GUICtrlSetData($NameOverride,IniRead($msnapplist,$app,"name","")) GUICtrlSetData($AppPrefix,IniRead($msnapplist,$app,"prefix","")) GUICtrlSetData($AppSuffix,IniRead($msnapplist,$app,"suffix","")) Switch IniRead($msnapplist,$app,"type",0) Case 0 GUICtrlSetState($TypeM,$GUI_CHECKED) Case 1 GUICtrlSetState($TypeG,$GUI_CHECKED) Case 2 GUICtrlSetState($TypeO,$GUI_CHECKED) EndSwitch $showexample=1 Case $DeleteApp if GUICtrlRead($AppList) then IniDelete($msnapplist,GUICtrlRead($AppList)) $inilist = IniReadSectionNames($msnapplist) if @error then msgbox(0,"Error","Could not read MSN App List for configuration") Exit Else $list="" For $i = 1 to $inilist[0] if $inilist[$i] <> "options" then $list&=$inilist[$i] & "|" Next GUICtrlSetData($AppList,"") GUICtrlSetData($AppList,stringtrimright($list,1)) EndIf $showexample=1 Case $NewApp $file=FileOpenDialog("Select an application to track",".","Applications (*.exe)|Binary files (*.bin)|All files (*.*)",1,"",$ConfigWND) if NOT @Error Then $file1=stringsplit($file,"\") $file=$file1[$file1[0]] $inilist = IniReadSectionNames(@ScriptDir & "\msnapplist.ini") if @error then msgbox(0,"Error","Could not read MSN App List for configuration") Exit Else $list="" For $i = 1 to $inilist[0] if $inilist[$i] <> "options" then $list&=$inilist[$i] & "|" Next if NOT StringInStr($list,$file,2) then $list&=$file Else $list=StringTrimRight($list,1) EndIf GUICtrlSetData($AppList,"") GUICtrlSetData($AppList,$list,$file) EndIf $app=$file GUICtrlSetData($NameOverride,IniRead($msnapplist,$app,"name","")) GUICtrlSetData($AppPrefix,IniRead($msnapplist,$app,"prefix","")) GUICtrlSetData($AppSuffix,IniRead($msnapplist,$app,"suffix","")) Switch IniRead($msnapplist,$app,"type",0) Case "0" GUICtrlSetState($TypeM,$GUI_CHECKED) Case "1" GUICtrlSetState($TypeG,$GUI_CHECKED) Case "2" GUICtrlSetState($TypeO,$GUI_CHECKED) EndSwitch EndIf $showexample=1 EndSwitch if $showexample Then $app=GUICtrlRead($AppList) if $app <> "" Then $example_type=IniRead($msnapplist,$app,"type",0) $example_prefix=IniRead($msnapplist,$app,"prefix",IniRead($msnapplist,"options","prefix" & $example_type,"")) if $example_prefix <> "" then $example_prefix&=" " $example_suffix=IniRead($msnapplist,$app,"suffix",IniRead($msnapplist,"options","suffix" & $example_type,"")) if $example_suffix <> "" then $example_suffix=" " & $example_suffix $example_name=IniRead($msnapplist,$app,"name","{AUTONAME}") GUICtrlSetData($ExampleDisplay,$example_prefix & $example_name & $example_suffix) else GUICtrlSetData($ExampleDisplay,"") EndIf $showexample=0 endif WEnd EndFunc while 1 $lastprocs = 0 $var = IniReadSectionNames($msnapplist) if @error Then msgbox(4096, "ERROR", "Error: 'msnapplist.ini' could not be read" & @CRLF & "Please check the file and try again") Exit EndIf Debug("msnapplist.ini Exists and is readable") if $var[0]-1 = 0 Then if $var[1] = "options" then TraySetState(4) TrayTip("Hey, Listen!","You don't have any applications set up. I know we prompted you to add some (I'm programmed to), so you must be REALLY lazy. How about you add some now? Doubleclick on this icon to bring up the Configuration tool, otherwise I'm a useless app!",10) Debug("MSNStatus is useless at this point, user has no defined applications.") EndIf Else TraySetState(8) EndIf $filetime = FileGetTime($msnapplist,0,1) $sleep = IniRead($msnapplist,"options","sleep",500) Debug("Loaded msnapplist into memory") while $filetime = FileGetTime($msnapplist,0,1) Debug("Applications tracked: " & $var[0]-1) for $i = 1 to $var[0] if $var[$i] = "options" then continueloop $appexe = $var[$i] Debug("Checking for '" & $appexe & "'") $appname = "" $lappname = "" $apptype=IniRead($msnapplist,$appexe,"type",2) $prefix=IniRead($msnapplist,$appexe,"prefix",IniRead($msnapplist,"options","prefix" & $apptype,0)) $suffix=IniRead($msnapplist,$appexe,"suffix",IniRead($msnapplist,"options","suffix" & $apptype,0)) while processexists($appexe) Debug("Tracking process: " & $appexe) $pidname = _Process2Win($appexe) while _Win2Process($pidname) <> $appexe AND processexists($appexe) $pidname = _Process2Win($appexe) Debug("Retrying to match process to window [PIDNAME]") sleep($sleep) WEnd $appname=IniRead($msnapplist,$appexe,"name",$pidname) if $prefix then $appname = $prefix & " " & $appname if $suffix then $appname = $appname & " " & $suffix if $appname <> $lappname then Debug("Found process: " & $appexe & " with title: " & $appname) ChangeMSNMessage($apptype,True,$appname) $setstatus=1 Debug("Updated status") $lappname = $appname EndIf sleep($sleep) WEnd if $appname then ChangeMSNMessage(0,False,"") $setstatus=0 Debug("Cleared status") EndIf sleep(1) Next $procs = ProcessList() while $procs[0][0] = $lastprocs $procs = ProcessList() Debug("Checked processes") sleep(ceiling($sleep/10)) WEnd Debug("New process detected (Process count changed)") $lastprocs = $procs[0][0] sleep($sleep) WEnd TrayTip("Application list has changed!", "Reloading the list", 2) Debug("Application list changed, reloaded") sleep($sleep) WEndWhat this does is cycle through every 500ms (default) and get a list of the running processes, then cycles through that list waiting on each item for 1/10th that time (to keep CPU usage down), and if it detects a process name listed in the INI configuration file, then it'll wait for that application to close, and update your MSN status via CoePSX's library to reflect whatever you choose to have it say. I haven't commented the code, but it's pretty straight forward. I hope somebody gets something out of this, cause frankly, me and my friends love not having to keep the damned Steam Friends list open all the time (especially since the Steam Friends/Messenger server tends to go down a lot) to see who's playing what.Attached to the post is a compiled copy of this script, ready to rock and roll if you just want to use the application. Advisable you put it in the WLM folder and then put a shortcut in the Startup folder on the Start Menu. The configuration tool window is a recent addition to the script, and really wraps things up nicely.Comments/suggestions/additions welcome of course, especially being that I'm a new AutoIt user.As an example (since a script won't do at this point), add the application Firefox.exe or Iexplore.exe and then sit there and watch what happens when you switch pages, but don't browse to any porn sites, definitely don't want the family and co-workers seeing that show up on your personal status, hehe.MSNStatus.zip Edited May 22, 2009 by Cynagen Blah, blah, blah... lip service... lip service.Working on a number of projects right now, just waiting for my time to post them here on AutoIt forums. Link to comment Share on other sites More sharing options...
Cynagen Posted May 24, 2009 Author Share Posted May 24, 2009 I see views and downloads, no comments? Blah, blah, blah... lip service... lip service.Working on a number of projects right now, just waiting for my time to post them here on AutoIt forums. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now