Updated setup_scheduler.ps1
This commit is contained in:
1 parent
2a34d0cc93
commit
5f33d8bd5d
1 file changed
+21
-17
+21
-17
@@ -1,26 +1,30 @@
|
|||||||
# Setup Task Scheduler for Journey FM Playlist Updater
|
# Setup Task Scheduler for Journey FM Playlist Updater
|
||||||
# Run this script as Administrator to create scheduled tasks
|
# Run this script as Administrator to create scheduled tasks
|
||||||
|
|
||||||
|
param(
|
||||||
|
[string]$Type = "Both", # Interval, Startup, Both
|
||||||
|
[int]$Interval = 15,
|
||||||
|
[string]$Unit = "Minutes" # Minutes, Hours, Days
|
||||||
|
)
|
||||||
|
|
||||||
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||||
$psScript = "$scriptDir\run_journey_playlist.ps1"
|
$psScript = "$scriptDir\run_journey_playlist.ps1"
|
||||||
|
|
||||||
# Task 1: Run every 15 minutes
|
if ($Type -eq "Interval" -or $Type -eq "Both") {
|
||||||
$action1 = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File `"$psScript`""
|
$action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File `"$psScript`""
|
||||||
$trigger1 = New-ScheduledTaskTrigger -Once -At (Get-Date).AddMinutes(1) -RepetitionInterval (New-TimeSpan -Minutes 15)
|
$trigger = New-ScheduledTaskTrigger -Once -At (Get-Date).AddMinutes(1) -RepetitionInterval (New-TimeSpan -$Unit $Interval)
|
||||||
$settings1 = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable
|
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable
|
||||||
|
Register-ScheduledTask -TaskName "Journey FM Playlist Updater - Every $Interval $Unit" -Action $action -Trigger $trigger -Settings $settings -Description "Updates Plex playlist with recently played songs every $Interval $Unit"
|
||||||
|
Write-Host "Created task: Every $Interval $Unit" -ForegroundColor Green
|
||||||
|
}
|
||||||
|
|
||||||
Register-ScheduledTask -TaskName "Journey FM Playlist Updater - Every 15 Minutes" -Action $action1 -Trigger $trigger1 -Settings $settings1 -Description "Updates Plex playlist with recently played songs from Journey FM every 15 minutes" -Force
|
if ($Type -eq "Startup" -or $Type -eq "Both") {
|
||||||
|
$action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File `"$psScript`""
|
||||||
# Task 2: Run at startup
|
$trigger = New-ScheduledTaskTrigger -AtStartup
|
||||||
$action2 = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File `"$psScript`""
|
$trigger.Delay = "PT1M" # 1 minute delay
|
||||||
$trigger2 = New-ScheduledTaskTrigger -AtStartup
|
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable
|
||||||
$trigger2.Delay = "PT1M" # 1 minute delay after startup
|
Register-ScheduledTask -TaskName "Journey FM Playlist Updater - At Startup" -Action $action -Trigger $trigger -Settings $settings -Description "Updates Plex playlist with recently played songs at startup"
|
||||||
$settings2 = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable
|
Write-Host "Created task: At Startup" -ForegroundColor Green
|
||||||
|
}
|
||||||
Register-ScheduledTask -TaskName "Journey FM Playlist Updater - At Startup" -Action $action2 -Trigger $trigger2 -Settings $settings2 -Description "Updates Plex playlist with recently played songs from Journey FM at computer startup" -Force
|
|
||||||
|
|
||||||
Write-Host "Scheduled tasks created successfully!" -ForegroundColor Green
|
Write-Host "Scheduled tasks created successfully!" -ForegroundColor Green
|
||||||
Write-Host "Task 1: Runs every 15 minutes" -ForegroundColor Cyan
|
|
||||||
Write-Host "Task 2: Runs at computer startup (with 60 second delay)" -ForegroundColor Cyan
|
|
||||||
Write-Host ""
|
|
||||||
Write-Host "You can view and manage these tasks in Task Scheduler." -ForegroundColor Yellow
|
|
||||||
Reference in new issue
Block a user