This page looks best with JavaScript enabled

Automating Chatty Maintenance With PowerShell

 ·  ☕ 3 min read

chattyshell

Today’s post is another PowerShell script I wrote with a very specific task in mind. Chatty is a popular chat application for streaming site Twitch.tv. It is generally used for interacting in channel chat rooms as well as logging, running scripts, and live statistics. Some users run it 24/7. One problem that exists is that the logs don’t get separated, even if the program is restarted, the log continues on in the same file. Over time this log file can get rather large. Additionally Chatty needs to exit gracefully to save any configuration changes. So why would you want to do run Chatty 24/7? Logging chat can be useful for a variety of reasons, most of them are related to the safety of both the streamer and the chat room. Chatty can be configured to log more than just what is typed into the chat room and although not the only solution or necessarily the best, it’s better than nothing. So, put simply I needed a script to gracefully close Chatty, rename the log file to the current date and time and then start Chatty again, in which case it would create a new log file for the chat room. Here’s the script I came up with.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# ----------------------------------
# Script: Chatty-Maintenance.ps1
# Author: Mike Galvin
# Date: 22/06/2016
# ----------------------------------
$Chatty = "C:\_Chatty"
$ChattyApp = "C:\apps\Chatty_0.8.3_hotkey_64bit\Chatty.jar"
$JavaApp = "C:\ProgramData\Oracle\Java\javapath\javaw.exe"
 
Get-Process javaw | Foreach-Object { $_.CloseMainWindow() | Out-Null }
Start-Sleep -s 10
move-item $Chatty\Logs\ChannelName.log ("$Chatty\Logs\ChannelName-{0:yyyy-MM-dd-HH-mm}.log" -f (get-date))
CD $Chatty\.chatty
& $JavaApp -jar $ChattyApp -cd $Chatty\.chatty

Once again let’s break it down to it’s components

1
2
3
$Chatty = "C:\_Chatty"
$ChattyApp = "C:\apps\Chatty_0.8.3_hotkey_64bit\Chatty.jar"
$JavaApp = "C:\ProgramData\Oracle\Java\javapath\javaw.exe"

Here I set the variables for the location of the Chatty profile, the Chatty application itself - the .jar file, and finally the location of the installed version of Java, which is actually a symlink. The reason I use this symlink is that rather than have to update this path every time Java is updated, the Java update process updates the symlink.

1
2
Get-Process javaw | Foreach-Object { $_.CloseMainWindow() | Out-Null }
Start-Sleep -s 10

Now the script gets and gracefully closes the Chatty application, and then waits for 10 seconds so the program has chance to write all it’s files out as it closes.

1
move-item $Chatty\Logs\ChannelName.log ("$Chatty\Logs\ChannelName-{0:yyyy-MM-dd-HH-mm}.log" -f (get-date))

Next we rename the active log file to include the current date and time, this way when Chatty restarts it will create a new log file.

1
2
CD $Chatty\.chatty
& $JavaApp -jar $ChattyApp -cd $Chatty\.chatty

Finally, Chatty is restarted. Due to how I have Chatty configured to store user settings, Chatty needs some extra start-up parameters and is very specific about them, hence why this last line looks needlessly repetitive. Now, if you create a task in Task Scheduler to run this once a day then you’ll have Chat logs separated by days and any configuration changes you make will be saved. As this is a PowerShell script, you’ll need to set the action as follows:

1
PowerShell.exe -ExecutionPolicy Bypass C:\PATH_TO_SCRIPT\Chatty-Maintenance.ps1

If you have any questions or comments please leave them below.

-Mike

Share on
Support the author with