Skip to content

Commit 6ef8400

Browse files
committed
Windows: install script, Start Menu shortcut with hotkey
- install-windows.ps1: copies binary, adds to user PATH, creates a Start Menu .lnk shortcut with Ctrl+Shift+R hotkey via WScript.Shell - docs/manual-shortcut-setup.md: Windows section with .lnk, PowerToys, and AutoHotkey alternatives - README: Windows subsection under Global keyboard shortcut
1 parent d581cf7 commit 6ef8400

3 files changed

Lines changed: 143 additions & 0 deletions

File tree

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,17 @@ After building the binary, run the install script:
8181

8282
The script copies the binary and creates an Automator Quick Action ("Launch Screen Ruler"). Then bind a shortcut (e.g. **⌘⇧R**) in **System Settings → Keyboard → Keyboard Shortcuts → Services**.
8383

84+
### Windows
85+
86+
After building the executable, run the install script in PowerShell:
87+
88+
```powershell
89+
.\install-windows.ps1 # installs to the current directory
90+
.\install-windows.ps1 -InstallDir "$env:LOCALAPPDATA\screen-ruler" # or specify a directory
91+
```
92+
93+
The script copies the binary, adds it to the user `PATH`, and creates a Start Menu shortcut with a **Ctrl+Shift+R** hotkey.
94+
8495
---
8596

8697
For manual setup on any platform, see [docs/manual-shortcut-setup.md](docs/manual-shortcut-setup.md).

docs/manual-shortcut-setup.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,29 @@ Any launcher or shortcut manager that can run an arbitrary command will work. Po
8888
### Option 3: Third-party tools
8989

9090
Apps like [Raycast](https://www.raycast.com/), [Alfred](https://www.alfredapp.com/), or [Hammerspoon](https://www.hammerspoon.org/) can bind a global hotkey to run an arbitrary command. Point it at the `screen-ruler` binary.
91+
92+
## Windows
93+
94+
### Option 1: Start Menu shortcut hotkey
95+
96+
1. Place `screen-ruler.exe` in a permanent directory.
97+
2. Create a shortcut (`.lnk`) to it in the **Start Menu** folder:
98+
- Press `Win+R`, type `shell:programs`, and press Enter.
99+
- Right-click → **New → Shortcut**, point it at `screen-ruler.exe`.
100+
3. Right-click the shortcut → **Properties****Shortcut key**, press your preferred combo (e.g. **Ctrl+Shift+R**) → **OK**.
101+
102+
> The hotkey only works while the `.lnk` remains in the Start Menu or Desktop folder.
103+
104+
### Option 2: PowerToys
105+
106+
[PowerToys Keyboard Manager](https://learn.microsoft.com/en-us/windows/powertoys/keyboard-manager) can remap a key combination to launch an application. Add a shortcut that runs `screen-ruler.exe`.
107+
108+
### Option 3: AutoHotkey
109+
110+
Create an `.ahk` script:
111+
112+
```ahk
113+
^+r::Run "C:\path\to\screen-ruler.exe"
114+
```
115+
116+
This binds **Ctrl+Shift+R** to launch screen-ruler.

install-windows.ps1

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<#
2+
.SYNOPSIS
3+
Install screen-ruler and register a global keyboard shortcut on Windows.
4+
5+
.DESCRIPTION
6+
Copies the built screen-ruler.exe binary to an install directory (default:
7+
current directory), creates a Start Menu shortcut with a Ctrl+Shift+R
8+
hotkey, and adds the binary to the user PATH.
9+
10+
.PARAMETER InstallDir
11+
Directory to install the binary into (default: current directory).
12+
13+
.EXAMPLE
14+
.\install-windows.ps1
15+
.\install-windows.ps1 -InstallDir "$env:LOCALAPPDATA\screen-ruler"
16+
#>
17+
18+
param(
19+
[string]$InstallDir = (Get-Location).Path
20+
)
21+
22+
Set-StrictMode -Version Latest
23+
$ErrorActionPreference = 'Stop'
24+
25+
$AppName = 'Screen Ruler'
26+
$AppId = 'screen-ruler'
27+
$Binary = Join-Path $PSScriptRoot 'dist' 'screen-ruler.exe'
28+
29+
# --- Locate the built binary ------------------------------------------------
30+
31+
if (-not (Test-Path $Binary)) {
32+
Write-Error "Binary not found at $Binary.`nBuild it first: pyinstaller screen_ruler.spec" -ErrorAction Continue
33+
exit 1
34+
}
35+
36+
# --- Copy binary to install dir ---------------------------------------------
37+
38+
if (-not (Test-Path $InstallDir)) {
39+
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
40+
}
41+
$InstallDir = (Resolve-Path $InstallDir).Path
42+
$ExecPath = Join-Path $InstallDir "$AppId.exe"
43+
44+
$BinaryFull = (Resolve-Path $Binary).Path
45+
if ($ExecPath -ne $BinaryFull) {
46+
Copy-Item -Path $BinaryFull -Destination $ExecPath -Force
47+
Write-Host "Installed binary -> $ExecPath"
48+
} else {
49+
Write-Host "Binary already at $ExecPath"
50+
}
51+
52+
# --- Add to user PATH (if not already present) ------------------------------
53+
54+
$userPath = [Environment]::GetEnvironmentVariable('Path', 'User')
55+
56+
# Normalize install directory for comparison
57+
$normalizedInstallDir = [IO.Path]::GetFullPath($InstallDir).TrimEnd('\').ToLowerInvariant()
58+
59+
# Split existing PATH into entries, normalize, and check for presence
60+
$pathEntries = @()
61+
if (-not [string]::IsNullOrEmpty($userPath)) {
62+
$pathEntries = $userPath -split ';' | Where-Object { -not [string]::IsNullOrWhiteSpace($_) }
63+
}
64+
65+
$hasInstallDir = $false
66+
foreach ($entry in $pathEntries) {
67+
$normalizedEntry = [IO.Path]::GetFullPath($entry).TrimEnd('\').ToLowerInvariant()
68+
if ($normalizedEntry -eq $normalizedInstallDir) {
69+
$hasInstallDir = $true
70+
break
71+
}
72+
}
73+
74+
if (-not $hasInstallDir) {
75+
if ([string]::IsNullOrEmpty($userPath)) {
76+
$newPath = $InstallDir
77+
} else {
78+
$newPath = "$userPath;$InstallDir"
79+
}
80+
[Environment]::SetEnvironmentVariable('Path', $newPath, 'User')
81+
Write-Host "Added $InstallDir to user PATH (restart your terminal to pick it up)."
82+
}
83+
84+
# --- Create Start Menu shortcut with hotkey ---------------------------------
85+
86+
$startMenu = [Environment]::GetFolderPath('StartMenu')
87+
$programsDir = Join-Path $startMenu 'Programs'
88+
$lnkPath = Join-Path $programsDir "$AppName.lnk"
89+
90+
$shell = New-Object -ComObject WScript.Shell
91+
$shortcut = $shell.CreateShortcut($lnkPath)
92+
$shortcut.TargetPath = $ExecPath
93+
$shortcut.Description = 'Measure on-screen UI elements using edge detection'
94+
$shortcut.WorkingDirectory = $InstallDir
95+
# Hotkey format: "Modifier+Key" — Ctrl+Shift+R
96+
$shortcut.Hotkey = 'Ctrl+Shift+R'
97+
$shortcut.Save()
98+
99+
Write-Host "Created Start Menu shortcut -> $lnkPath"
100+
Write-Host " Hotkey: Ctrl+Shift+R"
101+
102+
# --- Done -------------------------------------------------------------------
103+
104+
Write-Host ''
105+
Write-Host "Done. Press Ctrl+Shift+R to launch $AppName."
106+
Write-Host 'Note: the shortcut hotkey requires the .lnk to stay in the Start Menu folder.'

0 commit comments

Comments
 (0)