-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_task.ps1
More file actions
58 lines (50 loc) · 2.52 KB
/
setup_task.ps1
File metadata and controls
58 lines (50 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# setup_task.ps1
# Registers Auto Sort Folder as a Windows logon task.
#
# HOW TO RUN:
# 1. Open PowerShell on Windows (not WSL) — no admin needed.
# 2. Navigate to this folder (replace YOUR_WSL_DISTRO and YOUR_WSL_USERNAME):
# cd "\\wsl$\YOUR_WSL_DISTRO\home\YOUR_WSL_USERNAME\Auto-Sort-Folder"
# 3. Allow the script to run (one-time):
# Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned
# 4. Run:
# .\setup_task.ps1
#
# TO REMOVE THE TASK LATER:
# Unregister-ScheduledTask -TaskName "AutoSortFolder" -Confirm:$false
$TaskName = "AutoSortFolder"
# Auto-detect the WSL username so this works on any machine
$WslUser = (wsl whoami).Trim()
$ScriptPath = "/home/$WslUser/Auto-Sort-Folder/gui.py"
# ── Action: call wsl.exe which invokes Python inside your default distro ──
$action = New-ScheduledTaskAction `
-Execute "wsl.exe" `
-Argument "python3 $ScriptPath"
# ── Trigger: fire when the current Windows user logs on ───────────────────
$trigger = New-ScheduledTaskTrigger -AtLogOn -User $env:USERNAME
# ── Settings ──────────────────────────────────────────────────────────────
$settings = New-ScheduledTaskSettingsSet `
-ExecutionTimeLimit 0 `
-AllowStartIfOnBatteries `
-DontStopIfGoingOnBatteries
# ── Principal: run as the current user, no elevation required ─────────────
$principal = New-ScheduledTaskPrincipal `
-UserId "$env:USERDOMAIN\$env:USERNAME" `
-LogonType Interactive `
-RunLevel Limited
# ── Register ──────────────────────────────────────────────────────────────
Register-ScheduledTask `
-TaskName $TaskName `
-Action $action `
-Trigger $trigger `
-Settings $settings `
-Principal $principal `
-Description "Watches your Downloads folder and sorts files automatically." `
-Force | Out-Null
Write-Host ""
Write-Host " Task '$TaskName' registered successfully." -ForegroundColor Green
Write-Host " Auto Sort Folder will launch automatically at your next logon." -ForegroundColor Green
Write-Host ""
Write-Host " To remove it later, run:" -ForegroundColor Gray
Write-Host " Unregister-ScheduledTask -TaskName '$TaskName' -Confirm:`$false" -ForegroundColor Gray
Write-Host ""