add fast install script

This commit is contained in:
Peter 2023-08-05 17:36:27 +08:00
parent 82f8684973
commit 0fe6e9a31e
4 changed files with 34 additions and 5 deletions

View File

@ -1,11 +1,19 @@
# `numlock-indicator` # `numlock-indicator`
**\* Important: You'll need to manually use taskbar settings to pin the taskbar icon so it's always visible!**
This powershell script adds a small indicator to the system tray to indicate when the numlock is enabled. This powershell script adds a small indicator to the system tray to indicate when the numlock is enabled.
## Install
1. Run `install.ps1` in an **administrator** powershell terminal. This script will add a task scheduler task to start up the indicator on login. Admin privileges are required to add task scheduler tasks.
2. **\* ⚠Important: You'll need to manually use taskbar settings to pin the taskbar icon so it's always visible!**
## Old installation method
**\* ⚠Important: You'll need to manually use taskbar settings to pin the taskbar icon so it's always visible!**
Copy files to some directory and run `powershell systray.ps1`. You can also run `start.sh` to ensure that one copy of the script is always active. Copy files to some directory and run `powershell systray.ps1`. You can also run `start.sh` to ensure that one copy of the script is always active.
I wrote this because for some reason, my laptop keyboard has no LED indicator for the numlock key (yet they have one for capslock and speakers???) I wrote this because for some reason, my laptop keyboard has no LED indicator for the numlock key (yet they have one for capslock and speakers???)
Feel free to replace `icon.png` with any bitmap icon if you don't like my terrible pixel art. Feel free to replace `icon.png` with any bitmap icon if you don't like my terrible pixel art.

17
install.ps1 Normal file
View File

@ -0,0 +1,17 @@
$TaskName = "numlock-indicator"
$ScriptPath = Join-Path $PSScriptRoot "start.ps1"
$Action = New-ScheduledTaskAction -Execute 'C:\Windows\System32\WindowsPowerShell\v1.0\PowerShell.exe' -Argument "-WindowStyle Hidden -File `"$ScriptPath`""
$Trigger = New-ScheduledTaskTrigger -AtLogon
$Settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries
if (!$(Get-ScheduledTask -TaskName $TaskName -ErrorAction SilentlyContinue)) {
Register-ScheduledTask -TaskName $TaskName -Action $Action -Trigger $Trigger -Settings $Settings -User $env:USERNAME
if (Get-ScheduledTask -TaskName $TaskName -ErrorAction SilentlyContinue) {
Start-ScheduledTask -TaskName $TaskName
Write-Output "Task '$TaskName' created successfully."
} else {
Write-Output "Failed task creation. Run this script in admin mode."
}
} else {
Write-Output "Task '$TaskName' already exists."
}

4
start.ps1 Normal file
View File

@ -0,0 +1,4 @@
# Ensures one copy of the program is always active. Not necessary for operation.
while (1) {
powershell $(Join-Path $PSScriptRoot 'systray.ps1')
}

View File

@ -1,6 +1,6 @@
[System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms') | Out-Null [System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms') | Out-Null
$ICON_ON = [System.Drawing.Icon]::FromHandle(([System.Drawing.Bitmap]::FromFile($(Join-Path $pwd '\icon_on.png'))).GetHicon()) # Convert my png (bitmap) to an icon $ICON_ON = [System.Drawing.Icon]::FromHandle(([System.Drawing.Bitmap]::FromFile($(Join-Path $PSScriptRoot '\icon_on.png'))).GetHicon()) # Convert my png (bitmap) to an icon
$ICON_OFF = [System.Drawing.Icon]::FromHandle(([System.Drawing.Bitmap]::FromFile($(Join-Path $pwd '\icon_off.png'))).GetHicon()) $ICON_OFF = [System.Drawing.Icon]::FromHandle(([System.Drawing.Bitmap]::FromFile($(Join-Path $PSScriptRoot '\icon_off.png'))).GetHicon())
# $ICON_ON = [System.Drawing.Icon]::ExtractAssociatedIcon() # Feel free to use a system icon # $ICON_ON = [System.Drawing.Icon]::ExtractAssociatedIcon() # Feel free to use a system icon
# $ICON_OFF = [System.Drawing.Icon]::ExtractAssociatedIcon() # $ICON_OFF = [System.Drawing.Icon]::ExtractAssociatedIcon()