diff --git a/foam_sync.ps1 b/foam_sync.ps1 index 9b14a6b..7cf8018 100644 --- a/foam_sync.ps1 +++ b/foam_sync.ps1 @@ -1,19 +1,18 @@ #Requires -Version 5.1 +Set-StrictMode -Version 3.0 -$task = @{ - name = 'FoamGitSync' - description = "Periodically synchronizes the Git repository at $scriptDir using $scriptName." - freqencyMinutes = 2 -} +$scriptPath = $MyInvocation.MyCommand.Path +$scriptDir = Split-Path -Path $scriptPath -Parent +$logDir = Join-Path -Path $scriptDir -ChildPath ".logs" +$logName = "foam_sync.log" +$logFilePath = Join-Path -Path $logDir -ChildPath $logName +$scriptName = (Get-Item $scriptPath).Name -# --- Configuration --- -$frequencyMinutes = $task.freqencyMinutes # How often the Scheduled Task should attempt to run this script -$taskName = $task.name +# --- Task Setup --- +$taskName = 'FoamGitSync' +$taskDescription = "Periodically synchronizes the Git repository at $scriptDir using $scriptName." +$frequencyMinutes = 2 -# --- Log File Setup --- -# Log inside the repository, in a .logs subfolder. Ensure this is in .gitignore -$scriptDirForLog = $PSScriptRoot # Use PSScriptRoot for robustness in determining script's dir -$logDir = Join-Path -Path $scriptDirForLog -ChildPath ".logs" if (-not (Test-Path -Path $logDir)) { New-Item -ItemType Directory -Path $logDir -Force | Out-Null } @@ -22,9 +21,7 @@ $logFilePath = Join-Path -Path $logDir -ChildPath "foam_sync.log" Start-Transcript -Path $logFilePath -Append -IncludeInvocationHeader -Force try { - $scriptPath = $MyInvocation.MyCommand.Path - $scriptDir = Split-Path -Path $scriptPath -Parent - $scriptName = (Get-Item $scriptPath).Name + Write-Host "Script: $scriptName at $scriptPath" Write-Host "Repository directory: $scriptDir"