/ native-host / install-startup-task.ps1
install-startup-task.ps1
1 # Mnemonic Workspaces Bridge - Task Scheduler Setup 2 # Run this script as Administrator to create a startup task 3 4 $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path 5 $PythonScript = Join-Path $ScriptDir "workspaces-bridge.py" 6 $TaskName = "MnemonicWorkspacesBridge" 7 8 # Check if task already exists 9 $existingTask = Get-ScheduledTask -TaskName $TaskName -ErrorAction SilentlyContinue 10 11 if ($existingTask) { 12 Write-Host "Task '$TaskName' already exists. Removing old task..." -ForegroundColor Yellow 13 Unregister-ScheduledTask -TaskName $TaskName -Confirm:$false 14 } 15 16 # Create the action - run Python with the bridge script 17 $Action = New-ScheduledTaskAction -Execute "python" -Argument "`"$PythonScript`"" 18 19 # Create the trigger - at logon of current user 20 $Trigger = New-ScheduledTaskTrigger -AtLogOn -User $env:USERNAME 21 22 # Create settings 23 $Settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable -ExecutionTimeLimit (New-TimeSpan -Days 9999) 24 25 # Create the principal (run as current user) 26 $Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -LogonType Interactive -RunLevel Limited 27 28 # Register the task 29 Register-ScheduledTask -TaskName $TaskName -Action $Action -Trigger $Trigger -Settings $Settings -Principal $Principal -Description "Mnemonic Workspaces REST Bridge for browser extension sync" 30 31 Write-Host "" 32 Write-Host "Task '$TaskName' created successfully!" -ForegroundColor Green 33 Write-Host "" 34 Write-Host "The bridge will start automatically when you log in." 35 Write-Host "To start it now, run: schtasks /run /tn $TaskName" 36 Write-Host "To remove: Unregister-ScheduledTask -TaskName $TaskName" 37 Write-Host ""