PowerShell script to generate a Rainmeter skin

I recently discovered Rainmeter, a desktop customization tool that lets you use some really nice looking gadgets. I wanted a simple skin to show disk free space.

rainmeterskin

I have five volumes, I could have manually written a custom skin. (Rainmeter skins are INI files.) That would involve setting a measure section for each disk and a in another section define how the output looks. Or I could take the much more time consuming task of writing a PowerShell script to iterate through my disks and write the skin INI file.

Download RainmeterDisksSkin.ZIP

The body of the script:

# Stop on the first error
$ErrorActionPreference = "Stop"

$RainmeterPath = [environment]::getfolderpath("mydocuments") + "\Rainmeter\Skins\"
$SkinName = "Kenward"
$FileName = "disks.ini"

If (-Not (Test-Path $($RainmeterPath + $SkinName))) {
    Set-Location $RainmeterPath
    mkdir $SkinName
    }

$OutFile = $RainmeterPath + $SkinName + "\" + $FileName
$Disks = Get-Volume | where {$_.DriveType -eq "Fixed"} | sort -Property DriveLetter
$Disks

$Header = @"
[Rainmeter]
Update=1000

[Variables]
vFontName=Segoe UI Light
vFontColor=255,255,255,255
vSolidColor=0,0,0,128
vFontSize=14
vStringCase=Lower
"@

$MeterCommon = @"
`n[MeterDriveInfo]
NumOfDecimals=0
FontFace=#vFontName#
FontSize=#vFontSize#
Meter=String
X=0
Y=0
FontColor=#vFontColor#
SolidColor=#vSolidColor#
AntiAlias=1
AutoScale=1
StringCase=#vStringCase#
"@

Out-File -FilePath $Outfile -InputObject $Header

foreach ($Disk in $Disks) {
    Out-File -FilePath $Outfile -Append -InputObject "`n[MeasureFreeDiskSpace$($Disk.DriveLetter)]"
    Out-File -FilePath $Outfile -Append -InputObject "Measure=FreeDiskSpace"
    Out-File -FilePath $Outfile -Append -InputObject "Drive=$($Disk.DriveLetter):"
    Out-File -FilePath $Outfile -Append -InputObject "UpdateDivider=5"
    }

Out-File -FilePath $Outfile -Append -InputObject $MeterCommon

for ($i = 0; $i -le $Disks.count - 1; $i++)
    { 
    if ($i -eq 0) {
        $Output = "MeasureName=MeasureFreeDiskSpace$($Disks[$i].DriveLetter)"
        $TextValue = "text = ""$($Disks[$i].DriveLetter) drive %1B free"
        }
        else {
            $Output = "MeasureName$($i+1)=MeasureFreeDiskSpace$($Disks[$i].DriveLetter)"
            $TextValue += "#crlf#$($Disks[$i].DriveLetter) drive %$($i + 1)B free"
        }
    Out-File -FilePath $Outfile -Append -InputObject $Output
    }

Out-File -FilePath $Outfile -Append -InputObject $($TextValue + '"')

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *