Skip to content

Instantly share code, notes, and snippets.

@rasher
Last active April 15, 2021 10:08
Show Gist options
  • Save rasher/c2a4a83a11c42cb41f0b8095ff0f3066 to your computer and use it in GitHub Desktop.
Save rasher/c2a4a83a11c42cb41f0b8095ff0f3066 to your computer and use it in GitHub Desktop.
Monitor your Zwift log file and outputs the latest Ride On
# Copyright 2020 Jonas Häggqvist <rasher@rasher.dk>
#
# Usage of the works is permitted provided that this instrument is retained with the
# works, so that any entity that uses the works is notified of this instrument.
#
# DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.
# This script monitors your Zwift log file and outputs the latest Ride On to a given
# output file. The output file is updated at most every N ms (6000), to try and follow
# the Zwift GUI.
#
# Possible bug: If the log file is truncated or becomes smaller in any way, Powershell
# appears to panic and start outputting the entire file. Not sure there's any way to
# prevent that. May be fixed in new PowerShell versions? Written/tested on 5.1. It
# should not happen anyway unless Zwift does something really weird. This of course
# means it will.
$docs = [environment]::GetFolderPath("MyDocuments")
$zwift = "$docs\Zwift" # Zwift data directory
$log = "$zwift\Logs\Log.txt" # Path to Zwift log file
$output = "$zwift\Logs\LastRideon.txt" # File to write output to
$delay = 6000 # Delay in ms between updates of the file
$prefix = "" # Added in the logfile in front of the username
$postfix = " says Ride On!" # Added after the username
Function Write-SlowOutput {
[CmdletBinding()]
param (
[Parameter(Mandatory=$true,
HelpMessage="How long to pause for (ms)")]
[int32]$waitFor,
[Parameter(Mandatory=$false,
HelpMessage="File to output to")]
[string]$outputFile,
[Parameter(ValueFromPipeline)]
[Object]$input
)
BEGIN {}
PROCESS {
Write-Host $input
if ($outputFile) {
Out-File -Append -Encoding UTF8 -FilePath $outputFile -InputObject $input
}
Start-Sleep -Milliseconds $waitFor
}
END {}
}
Get-Content -Tail 0 -Wait -Encoding "UTF8" $log |
Select-String "HUD_Notify: (.*) says Ride On!" |
% {$prefix + $_.matches.groups[1].value} |
Write-SlowOutput -outputFile $output -waitFor $delay
@rasher
Copy link
Author

rasher commented May 2, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment