Stream Deck XL button to rotate and resize JPG
user: On my Stream Deck XL. I used to have a cool button I programmed to rotate and resize a jpg picture with Microsoft paint. and someone messed with the settings. and I'm trying to get working again.
So, now I'm trying to reprogram the button from scratch but I have been struggling with it for a long time, so I'm turning to you for advice. Basically how the button used to work, is I would open the picture, then hit the button. It would rotate the image 90 degrees. then I would resize the picture to 200 pixels wide/horizontal and then save the image. It would not have it save the orginal image. I would click with my mouse on the directory and then press enter after I entered the directory I wanted to save it to. Any advice would be great. its a fairly simply thing I'm trying to do, I did have it working great last month.
assistant: I’d solve this by making the Stream Deck button trigger a small script instead of trying to “drive” Paint with fragile keystrokes. I’ll give you the practical Paint-macro way too, but the script route is what will stay working.
assistant: The key detail: Paint itself is the weak link. A Stream Deck multi-action can run several steps in order, but one changed menu, focus issue, or dialog delay can break it; Elgato’s own docs show Multi Actions are just stacked actions separated by intervals, not a true image-processing engine.
assistant: Yes — I would **stop trying to make Paint do the whole job** and make the Stream Deck button run a tiny script. Paint is fine as the place where the picture is open, but the resizing/rotating/saving should be handled by Windows/PowerShell so it does not break every time Paint focus or menus change.
Stream Deck can trigger an app/script with the **System → Open** action, and it can also run chained actions with **Multi Action**, but Multi Action is still basically timed button presses, which is why Paint macros are fragile.
## Best setup: Paint stays open, Stream Deck runs a script
This will do what you described:
Open image in Paint → press Stream Deck button → script copies the image from Paint → rotates 90° → resizes to **200 px wide** → asks where to save → saves a new JPG → original stays untouched.
### 1. Create this folder
In Windows File Explorer, create:
```text
Documents\StreamDeckScripts
```
### 2. Create this PowerShell script
Open Notepad and paste this:
```powershell
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
# Get active window title so we can make a decent output filename
Add-Type @"
using System;
using System.Text;
using System.Runtime.InteropServices;
public class Win32 {
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
public static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);
}
"@
$sb = New-Object System.Text.StringBuilder 512
$hwnd = [Win32]::GetForegroundWindow()
[Win32]::GetWindowText($hwnd, $sb, $sb.Capacity) | Out-Null
$title = $sb.ToString()
$baseName = "rotated-resized-image"
if ($title -match "^(.*?)\s*-\s*Paint") {
$candidate = $matches[1]
$candidate = [System.IO.Path]::GetFileNameWithoutExtension($candidate)
if ($candidate.Trim().Length -gt 0) {
$baseName = $candidate
}
}
# Copy whole image from Paint
[System.Windows.Forms.SendKeys]::SendWait("^a")
Start-Sleep -Millis…
user: when I tried to test it, it does not work. i do have focus on the MS Paint but it when I hit the button, i see something briefly on my other monitor then it's gone
assistant: That brief flash is actually a useful clue: the script is probably opening a PowerShell/CMD window, stealing focus away from Paint, then failing or closing before you can read the error. The fix is to split the job: let Stream Deck copy the Paint image first, then run a script that only processes the clipboard.
assistant: That behavior means the button is launching the script, but the script is probably failing immediately. More importantly, my earlier version had a flaw: **when PowerShell opens, it can steal focus from Paint**, so the `Ctrl+A` / `Ctrl+C` part may be going to the PowerShell window instead of Paint.
Do this instead: make the Stream Deck button copy the image **before** launching PowerShell.
## Fix the setup
### Step 1: Replace the PowerShell script
Open this file:
```text
%USERPROFILE%\Documents\StreamDeckScripts\Paint-Rotate-Resize-Save.ps1
```
Replace everything inside it with this version:
```powershell
$ErrorActionPreference = "Stop"
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$logPath = "$env:USERPROFILE\Documents\StreamDeckScripts\last-run-log.txt"
function Write-Log {
param([string]$Message)
Add-Content -Path $logPath -Value "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - $Message"
}
try {
Write-Log "Script started."
Start-Sleep -Milliseconds 300
$image = $null
for ($i = 0; $i -lt 10; $i++) {
if ([System.Windows.Forms.Clipboard]::ContainsImage()) {
$image = [System.Windows.Forms.Clipboard]::GetImage()
break
}
Start-Sleep -Milliseconds 200
}
if ($null -eq $image) {
throw "No image found on clipboard. In Paint, the image must be copied first with Ctrl+A then Ctrl+C."
}
Write-Log "Image found on clipboard. Original size: $($image.Width)x$($image.Height)."
# Clone clipboard image into a bitmap
$source = New-Object System.Drawing.Bitmap $image
# Rotate 90 degrees clockwise
$source.RotateFlip([System.Drawing.RotateFlipType]::Rotate90FlipNone)
# Resize to 200 px wide
$newWidth = 200
$newHeight = [int][Math]::Round($source.Height * ($newWidth / $source.Width))
$output = New-Object System.Drawing.Bitmap $newWidth, $newHeight
$graphics = [System.Drawing.Graphics]::FromImage($output)
…
user: i tested it manually first. the test did not work, i saw the window blip again. and there is not a last run log file
assistant: No log file means the script likely never reached the first line of execution. I see a likely culprit in the PowerShell syntax I gave you: one of the JPG encoder lines can cause a parse error before logging even starts.
assistant: Good catch. **No log file** means the script is probably failing **before it even starts running**. That usually means one of three things:
1. The `.ps1` file path is wrong.
2. The file accidentally saved as `.ps1.txt`.
3. The PowerShell script has a parse/syntax error.
I also see a likely problem in the script I gave you: the JPG quality encoder line may be breaking before the script reaches the log line. Let’s simplify it and make the CMD window stay open so we can actually see the error.
## Step 1: Replace the `.cmd` file with this diagnostic version
Open:
```text
%USERPROFILE%\Documents\StreamDeckScripts\paint-resize-button.cmd
```
Replace everything with:
```bat
@echo off
set "SCRIPT=%USERPROFILE%\Documents\StreamDeckScripts\Paint-Rotate-Resize-Save.ps1"
set "LOG=%USERPROFILE%\Documents\StreamDeckScripts\debug-run-output.txt"
echo Launcher started > "%LOG%"
echo Script path: "%SCRIPT%" >> "%LOG%"
if not exist "%SCRIPT%" (
echo ERROR: PowerShell script was not found. >> "%LOG%"
echo.
echo ERROR: PowerShell script was not found:
echo "%SCRIPT%"
echo.
echo Check whether the file accidentally saved as .ps1.txt
echo.
pause
exit /b 1
)
powershell.exe -NoProfile -ExecutionPolicy Bypass -STA -File "%SCRIPT%" >> "%LOG%" 2>&1
echo. >> "%LOG%"
echo Exit code: %ERRORLEVEL% >> "%LOG%"
echo.
type "%LOG%"
echo.
pause
```
Now the black window should **stay open** instead of disappearing.
---
## Step 2: Replace the PowerShell script with this simpler working version
Open:
```text
%USERPROFILE%\Documents\StreamDeckScripts\Paint-Rotate-Resize-Save.ps1
```
Replace everything with this:
```powershell
$ErrorActionPreference = "Stop"
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$logPath = Join-Path $scriptDir "last-run-log.txt"
function Write-Log {
param([string]$Message)
Add-Content -Path $logPath -Value "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - $Message"
}
try {
Write-Log "Script started."
…
user: in the CMD window iit said press any key to continue, then when i hit enter it disappeared
assistant: That part is normal: **“Press any key to continue” means the diagnostic launcher reached the end**, and pressing Enter closes the window.
Now we need to read what happened **above** that line, or read the debug file it created.
Open this file in Notepad:
```text
%USERPROFILE%\Documents\StreamDeckScripts\debug-run-output.txt
```
Fastest way:
1. Press **Windows + R**
2. Paste this:
```text
notepad "%USERPROFILE%\Documents\StreamDeckScripts\debug-run-output.txt"
```
3. Press **Enter**
Then look for one of these:
```text
ERROR:
```
or:
```text
Exit code:
```
Also check whether this file exists:
```text
%USERPROFILE%\Documents\StreamDeckScripts\last-run-log.txt
```
Open it with:
```text
notepad "%USERPROFILE%\Documents\StreamDeckScripts\last-run-log.txt"
```
What I suspect happened: the script actually ran, but either:
- no image was on the clipboard,
- the folder picker opened behind another window,
- or the `.ps1` path is still wrong.
Try one more thing too: after `Ctrl+A` / `Ctrl+C` in Paint, open **WordPad**, **Paint**, or even a blank document and press `Ctrl+V`. If the image pastes, then the clipboard part is working. If it does not paste, Paint is not copying the full image the way we expect.
user: debug-run-output.txt is not in there
assistant: That tells us something important: the file you’re running is not the diagnostic `.cmd` we think it is, or Windows is saving/searching in a different Documents folder, often OneDrive Documents. Let’s remove that confusion completely.
assistant: That means we’re not running the diagnostic file we think we are, because this line should have created it **before PowerShell even starts**:
```bat
echo Launcher started > "%LOG%"
```
So let’s stop using `Documents` for now. Windows may be redirecting it to OneDrive, or Stream Deck may still be pointing at the old file.
## Do this reset: use a simple folder directly under your user folder
### 1. Press **Windows + R**
Paste this:
```text
%USERPROFILE%
```
Press **Enter**.
Inside that folder, create a new folder named:
```text
StreamDeckScripts
```
So the folder should be:
```text
C:\Users\YourName\StreamDeckScripts
```
Not Documents. Not OneDrive.
---
## 2. Create a simple test launcher first
Open Notepad and paste this:
```bat
@echo off
echo This launcher definitely ran.
echo This launcher definitely ran. > "%USERPROFILE%\StreamDeckScripts\TEST_CREATED_BY_CMD.txt"
echo.
echo I created this file:
echo "%USERPROFILE%\StreamDeckScripts\TEST_CREATED_BY_CMD.txt"
echo.
pause
```
Save it as:
```text
%USERPROFILE%\StreamDeckScripts\test-launcher.cmd
```
Important: in Notepad, choose **Save as type: All Files**.
The file must be:
```text
test-launcher.cmd
```
Not:
```text
test-launcher.cmd.txt
```
Now double-click `test-launcher.cmd`.
After it runs, go look in:
```text
%USERPROFILE%\StreamDeckScripts
```
You should see:
```text
TEST_CREATED_BY_CMD.txt
```
If that file does **not** appear, then the issue is definitely file-extension/path-related, not the image script.
---
## 3. Make File Explorer show extensions
This is worth doing right now:
1. Open File Explorer.
2. Click **View**.
3. Click **Show**.
4. Enable **File name extensions**.
Then look at your files. You may discover something like:
```text
paint-resize-button.cmd.txt
Paint-Rotate-Resize-Save.ps1.txt
```
If so, that is the problem.
---
## 4. Once the test launcher works, use this folder for the real files
Use these exact paths:
```text
%USERPROFILE%\StreamDeckScripts\Paint-…
user: its using one drive
assistant: That explains it. Windows has redirected your **Documents** folder into OneDrive, so we were probably looking in one place while the script was writing/running from another.
Do **not** use Documents for this Stream Deck button. Use a plain local folder:
```text
%USERPROFILE%\StreamDeckScripts
```
That should be something like:
```text
C:\Users\adam\StreamDeckScripts
```
## Do this now
Press **Windows + R**, paste this, and press **Enter**:
```text
%USERPROFILE%
```
Create this folder there:
```text
StreamDeckScripts
```
So the full folder is:
```text
%USERPROFILE%\StreamDeckScripts
```
Now move or recreate these two files inside that folder:
```text
Paint-Rotate-Resize-Save.ps1
paint-resize-button.cmd
```
## Your `.cmd` file should be this
Open `paint-resize-button.cmd` in Notepad and make it exactly this:
```bat
@echo off
set "SCRIPT=%USERPROFILE%\StreamDeckScripts\Paint-Rotate-Resize-Save.ps1"
echo Running launcher:
echo %~f0
echo.
echo Looking for script:
echo "%SCRIPT%"
echo.
if not exist "%SCRIPT%" (
echo ERROR: PowerShell script not found.
echo.
echo Make sure it is named exactly:
echo Paint-Rotate-Resize-Save.ps1
echo.
pause
exit /b 1
)
powershell.exe -NoProfile -ExecutionPolicy Bypass -STA -File "%SCRIPT%"
echo.
echo Exit code: %ERRORLEVEL%
echo.
pause
```
Then manually double-click:
```text
%USERPROFILE%\StreamDeckScripts\paint-resize-button.cmd
```
This time the window should clearly show where it is looking.
## Then update Stream Deck
In Stream Deck, make sure the **Open** action points to the new local file:
```text
%USERPROFILE%\StreamDeckScripts\paint-resize-button.cmd
```
Not the OneDrive Documents path.
## Why this matters
OneDrive commonly changes “Documents” to something like:
```text
C:\Users\adam\OneDrive\Documents
```
while you may think you are using:
```text
C:\Users\adam\Documents
```
That mismatch is exactly how you end up with no debug file where you expected it.
For scripts like…
user: so then that was the problem to begin with.
So, let's set use C:\1 folder for all scripts.
assistant: Yes — that was probably the original problem or at least a big part of it. Using `C:\1` is a good move here because it removes OneDrive, Documents redirection, and weird path confusion.
assistant: Yes. Let’s standardize everything to:
```text
C:\1
```
That removes the OneDrive mess.
## 1. Create the folder
Press **Windows + R**, paste:
```text
C:\1
```
If it says it does not exist, create it manually in File Explorer.
If Windows blocks you, open Command Prompt as Administrator and run:
```bat
mkdir C:\1
```
## 2. Create this PowerShell file
Open Notepad and paste this:
```powershell
$ErrorActionPreference = "Stop"
$scriptDir = "C:\1"
$logPath = Join-Path $scriptDir "paint-resize-log.txt"
function Write-Log {
param([string]$Message)
Add-Content -Path $logPath -Value "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - $Message"
}
try {
New-Item -ItemType Directory -Path $scriptDir -Force | Out-Null
Write-Log "Script started."
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
Start-Sleep -Milliseconds 500
if (-not [System.Windows.Forms.Clipboard]::ContainsImage()) {
throw "No image found on clipboard. Open image in Paint, press Ctrl+A, then Ctrl+C, then run this again."
}
$clipImage = [System.Windows.Forms.Clipboard]::GetImage()
if ($null -eq $clipImage) {
throw "Clipboard image was empty."
}
Write-Log "Clipboard image found. Original size: $($clipImage.Width)x$($clipImage.Height)."
$source = New-Object System.Drawing.Bitmap $clipImage
# Rotate 90 degrees clockwise
$source.RotateFlip([System.Drawing.RotateFlipType]::Rotate90FlipNone)
# Resize to 200 pixels wide while keeping aspect ratio
$newWidth = 200
$newHeight = [int][Math]::Round($source.Height * ($newWidth / $source.Width))
Write-Log "Output size: ${newWidth}x${newHeight}."
$output = New-Object System.Drawing.Bitmap $newWidth, $newHeight
$graphics = [System.Drawing.Graphics]::FromImage($output)
$graphics.InterpolationMode = [System.Drawing.Drawing2D.InterpolationMode]::HighQualityBicubic
$graphics.SmoothingMode = [System.Drawing.Drawing2D.Smooth…
user: that's really cool! now that I see how this works, it seems like we can do more elaborate stuff.
What I would like to do, is automatically save the jpg file with the same file name that as the original image. but have it save inside C:\Users\mcwlp\OneDrive\Desktop\WHITTENBURG BLUE 3523D 04H\PICS
Can we do that? if we can't save to the OneDrive folder. let's choose somewhere else
assistant: Absolutely. Now that the basic script concept works, we can make this much cleaner: Stream Deck copies the image from Paint, PowerShell reads Paint’s window title to get the original filename, then saves the rotated/resized JPG directly into your target PICS folder.
assistant: Yes, we can do that.
**OneDrive is fine** as long as this folder exists locally:
```text
C:\Users\mcwlp\OneDrive\Desktop\WHITTENBURG BLUE 3523D 04H\PICS
```
Keep your scripts in:
```text
C:\1
```
and save the finished image into the OneDrive PICS folder.
## Important behavior
This version will save the output using the **same filename Paint shows in the title bar**.
Example:
```text
IMG_1234.jpg
```
will save as:
```text
C:\Users\mcwlp\OneDrive\Desktop\WHITTENBURG BLUE 3523D 04H\PICS\IMG_1234.jpg
```
If that file already exists in the PICS folder, this script will **overwrite the copy in the PICS folder**. It should not overwrite the original unless the original image is also inside that same PICS folder.
## Replace your PowerShell script with this
Open:
```text
C:\1\Paint-Rotate-Resize-Save.ps1
```
Replace everything with:
```powershell
$ErrorActionPreference = "Stop"
$scriptDir = "C:\1"
$logPath = Join-Path $scriptDir "paint-resize-log.txt"
# Final save folder
$outputFolder = "C:\Users\mcwlp\OneDrive\Desktop\WHITTENBURG BLUE 3523D 04H\PICS"
function Write-Log {
param([string]$Message)
Add-Content -Path $logPath -Value "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - $Message"
}
try {
New-Item -ItemType Directory -Path $scriptDir -Force | Out-Null
New-Item -ItemType Directory -Path $outputFolder -Force | Out-Null
Write-Log "Script started."
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
# Try to get the original filename from the Paint window title
$paint = Get-Process |
Where-Object {
$_.ProcessName -match "mspaint|paint" -and
$_.MainWindowTitle -and
$_.MainWindowTitle.Trim().Length -gt 0
} |
Sort-Object StartTime -Descending |
Select-Object -First 1
$fileName = $null
if ($paint) {
$title = $paint.MainWindowTitle
Write-Log "Paint window title: $title"
# Usually looks like: …
user: i saw a CMD window blip. then nothing happened I don't see the pic saved. maybe because the save directory has a onedrive path
assistant: The OneDrive path might be part of it, but the bigger issue is we removed the `pause`, so any error is hidden again. Let’s make it show the error, and I’m also going to simplify the save path logic so it falls back to `C:\1\PICS` if OneDrive gives it trouble.
assistant: Yes, it **could** be the OneDrive save path, but right now the bigger problem is that the window is closing before we can see the error.
Let’s do two things:
1. Make the CMD window stay open again.
2. Use OneDrive as the first save choice, but automatically fall back to:
```text
C:\1\PICS
```
## 1. Replace `C:\1\paint-resize-button.cmd`
Open this file:
```text
C:\1\paint-resize-button.cmd
```
Replace it with:
```bat
@echo off
set "SCRIPT=C:\1\Paint-Rotate-Resize-Save.ps1"
set "CMDLOG=C:\1\paint-cmd-output.txt"
echo Launcher started > "%CMDLOG%"
echo Script: "%SCRIPT%" >> "%CMDLOG%"
echo. >> "%CMDLOG%"
if not exist "%SCRIPT%" (
echo ERROR: Script not found: "%SCRIPT%" >> "%CMDLOG%"
type "%CMDLOG%"
pause
exit /b 1
)
powershell.exe -NoProfile -ExecutionPolicy Bypass -STA -File "%SCRIPT%" >> "%CMDLOG%" 2>&1
echo. >> "%CMDLOG%"
echo Exit code: %ERRORLEVEL% >> "%CMDLOG%"
type "%CMDLOG%"
echo.
pause
```
Now if it fails, the black window will stay open.
---
## 2. Replace `C:\1\Paint-Rotate-Resize-Save.ps1`
Open:
```text
C:\1\Paint-Rotate-Resize-Save.ps1
```
Replace it with this cleaned-up version:
```powershell
$ErrorActionPreference = "Stop"
$scriptDir = "C:\1"
$logPath = Join-Path $scriptDir "paint-resize-log.txt"
$primaryOutputFolder = "C:\Users\mcwlp\OneDrive\Desktop\WHITTENBURG BLUE 3523D 04H\PICS"
$fallbackOutputFolder = "C:\1\PICS"
function Write-Log {
param([string]$Message)
Add-Content -Path $logPath -Value "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - $Message"
}
try {
New-Item -ItemType Directory -Path $scriptDir -Force | Out-Null
Write-Log "Script started."
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
# Choose save folder. Try OneDrive path first, otherwise use C:\1\PICS
$outputFolder = $primaryOutputFolder
try {
New-Item -ItemType Directory -Path $primaryOutputFolder -Force | Out-Null
Write-Log "Primary output folder ready: $primary…
user: Launcher started
Script: "C:\1\Paint-Rotate-Resize-Save.ps1"
At C:\1\Paint-Rotate-Resize-Save.ps1:49 char:51
+ ... $nameFromTitle = $title -replace "\s+[-â?"â?"]\s+Paint.*$", ""
+ ~~~~~~~~~~~~~~~~
Unexpected token 'â?"]\s+Paint.*$"' in expression or statement.
At C:\1\Paint-Rotate-Resize-Save.ps1:49 char:67
+ ... $nameFromTitle = $title -replace "\s+[-â?"â?"]\s+Paint.*$", ""
+ ~
Missing argument in parameter list.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken
Exit code: 1
Press any key to continue . . .
assistant: Yep — we found the exact problem.
This is **not OneDrive**. It is a text/encoding issue from the script copy/paste. The line with this part:
```text
[-–—]
```
got corrupted into:
```text
[-â?"â?"]
```
PowerShell cannot parse that.
## Quick fix
Open:
```text
C:\1\Paint-Rotate-Resize-Save.ps1
```
Find the broken line around line 49:
```powershell
$nameFromTitle = $title -replace "\s+[-â?"â?"]\s+Paint.*$", ""
```
Replace that entire line with this plain ASCII-safe version:
```powershell
$nameFromTitle = $title -replace "\s+-\s+Paint.*$", ""
```
Save the file.
Then test again:
1. Open image in Paint.
2. Press `Ctrl + A`
3. Press `Ctrl + C`
4. Double-click:
```text
C:\1\paint-resize-button.cmd
```
## Why it happened
That line was trying to handle different dash characters:
```text
- – —
```
But Windows/Notepad/PowerShell mangled the special dash characters during copy/paste. For this workflow, we do **not** need the fancy dash handling. Paint usually uses a normal hyphen:
```text
filename.jpg - Paint
```
So the plain version is better and safer.
## If you want the safest version
Use this instead of the broken line:
```powershell
$nameFromTitle = $title -replace "\s+.\s+Paint.*$", ""
```
But I would try this one first:
```powershell
$nameFromTitle = $title -replace "\s+-\s+Paint.*$", ""
```
That should get you past the parse error immediately.
user: Ok, but I just wanted to let you know, I was using Kate as my text editor this whole, time, I have no idea if that had anything to do with it.
The test worked, and I see it save the file as Paint-Rotate-Resize-Save.jpg inside C:\Users\mcwlp\OneDrive\Desktop\WHITTENBURG BLUE 3523D 04H\PICS
assistant: Good — that means the rotate/resize/save part is working. The remaining bug is just the filename detection.
Kate probably was **not the main problem**, but it may have preserved or converted special dash characters in a way PowerShell did not like. Going forward, we’ll keep the script **plain ASCII only** to avoid that.
The reason it saved as:
```text
Paint-Rotate-Resize-Save.jpg
```
is because this part of the script:
```powershell
$_.MainWindowTitle -match "Paint"
```
accidentally matched the **PowerShell/CMD window**, because the script filename itself contains the word `Paint`.
So instead of detecting the actual Paint app, it detected itself. Easy fix.
## Replace the Paint filename detection section
Open:
```text
C:\1\Paint-Rotate-Resize-Save.ps1
```
Find this section:
```powershell
# Get original filename from Paint window title
$paintWindow = Get-Process |
Where-Object {
$_.MainWindowTitle -and
$_.MainWindowTitle -match "Paint"
} |
Select-Object -First 1
$fileName = $null
if ($paintWindow) {
$title = $paintWindow.MainWindowTitle
Write-Log "Paint title: $title"
# Example: IMG_1234.jpg - Paint
$nameFromTitle = $title -replace "\s+-\s+Paint.*$", ""
$nameFromTitle = $nameFromTitle.Trim()
if ($nameFromTitle -and $nameFromTitle -notmatch "Untitled") {
$fileName = [System.IO.Path]::GetFileName($nameFromTitle)
}
}
```
Replace it with this safer version:
```powershell
# Get original filename from the actual Microsoft Paint process only
$paintWindow = Get-Process |
Where-Object {
$_.ProcessName -eq "mspaint" -and
$_.MainWindowTitle -and
$_.MainWindowTitle.Trim().Length -gt 0
} |
Select-Object -First 1
$fileName = $null
if ($paintWindow) {
$title = $paintWindow.MainWindowTitle
Write-Log "Paint title: $title"
# Example title: IMG_1234.jpg - Paint
$nameFromTitle = $title -replace "\s+-\s+Paint.*$", ""
$nameFromTitle = $nameFromTitle.T…
user: just give me the whole script, and I don't want a test mode. with the terminal open. Let's assume it will work.
assistant: Perfect. Use these two files.
## 1. PowerShell script
Save this as:
```text
C:\1\Paint-Rotate-Resize-Save.ps1
```
```powershell
$ErrorActionPreference = "Stop"
$scriptDir = "C:\1"
$logPath = Join-Path $scriptDir "paint-resize-log.txt"
$outputFolder = "C:\Users\mcwlp\OneDrive\Desktop\WHITTENBURG BLUE 3523D 04H\PICS"
function Write-Log {
param([string]$Message)
Add-Content -Path $logPath -Value "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - $Message"
}
try {
New-Item -ItemType Directory -Path $scriptDir -Force | Out-Null
New-Item -ItemType Directory -Path $outputFolder -Force | Out-Null
Write-Log "Script started."
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
# Get original filename from actual Microsoft Paint process only
$paintWindow = Get-Process |
Where-Object {
$_.ProcessName -eq "mspaint" -and
$_.MainWindowTitle -and
$_.MainWindowTitle.Trim().Length -gt 0
} |
Select-Object -First 1
$fileName = $null
if ($paintWindow) {
$title = $paintWindow.MainWindowTitle
Write-Log "Paint title: $title"
# Example Paint title: IMG_1234.jpg - Paint
$nameFromTitle = $title -replace "\s+-\s+Paint.*$", ""
$nameFromTitle = $nameFromTitle.Trim()
if ($nameFromTitle -and $nameFromTitle -notmatch "Untitled") {
$fileName = [System.IO.Path]::GetFileName($nameFromTitle)
}
}
if (-not $fileName) {
$timestamp = Get-Date -Format "yyyyMMdd_HHmmss"
$fileName = "paint_rotated_200w_$timestamp.jpg"
Write-Log "Could not detect original filename. Using fallback filename: $fileName"
}
# Force .jpg extension
$baseName = [System.IO.Path]::GetFileNameWithoutExtension($fileName)
$fileName = "$baseName.jpg"
# Remove illegal filename characters
$fileName = [regex]::Replace($fileName, '[<>:"/\\|?*]', '_')
$outputPath = Join-Path …
user: it works
assistant: Excellent. That’s a solid setup now.
Your working flow is:
```text
Open image in Paint
Press Stream Deck button
Ctrl+A / Ctrl+C happens
Script rotates 90 degrees
Resizes to 200 px wide
Saves to:
C:\Users\mcwlp\OneDrive\Desktop\WHITTENBURG BLUE 3523D 04H\PICS
```
A couple of practical notes:
Keep a backup copy of these two files somewhere safe:
```text
C:\1\Paint-Rotate-Resize-Save.ps1
C:\1\paint-resize-button.cmd
```
Also, the log file is useful if anything breaks later:
```text
C:\1\paint-resize-log.txt
```
Nice work sticking with it — this is exactly the kind of Stream Deck automation that becomes really powerful once the first one works.
user: what I would like it to do is close the paint window after I hit the button
assistant: Yes. The safest way is to have the **PowerShell script close the actual Paint window after the save succeeds**.
Do **not** add `Alt+F4` in Stream Deck. That could close the wrong window if focus changes.
## Add this block near the end of your PowerShell script
Open:
```text
C:\1\Paint-Rotate-Resize-Save.ps1
```
Find this section near the bottom:
```powershell
Write-Log "Saved image to: $outputPath"
$graphics.Dispose()
$output.Dispose()
$source.Dispose()
$clipImage.Dispose()
```
Change it to this:
```powershell
Write-Log "Saved image to: $outputPath"
$graphics.Dispose()
$output.Dispose()
$source.Dispose()
$clipImage.Dispose()
# Close the actual Paint window after successful save
if ($paintWindow -and -not $paintWindow.HasExited) {
Write-Log "Closing Paint window."
$paintWindow.CloseMainWindow() | Out-Null
}
```
That’s it.
## What this does
After the rotated/resized JPG is saved successfully, it sends a normal close command to Microsoft Paint. It should close the same Paint window it detected earlier.
If Paint ever shows a “Do you want to save changes?” prompt, that means Paint thinks the original file was changed. Since your Stream Deck action is only doing `Ctrl+A` and `Ctrl+C`, it normally should **not** trigger that prompt.
user: the curly brackets are lighting up yellow in kate. the section you are trying to show me does not have the brackets
assistant: You’re right — don’t try to patch that little section. Replace the **whole PowerShell script** so the braces all line up cleanly.
Kate lighting curly brackets yellow is usually just **bracket matching / syntax highlighting**, not necessarily an error. But to avoid confusion, use the full file below.
Replace everything in:
```text
C:\1\Paint-Rotate-Resize-Save.ps1
```
with this:
```powershell
$ErrorActionPreference = "Stop"
$scriptDir = "C:\1"
$logPath = Join-Path $scriptDir "paint-resize-log.txt"
$outputFolder = "C:\Users\mcwlp\OneDrive\Desktop\WHITTENBURG BLUE 3523D 04H\PICS"
function Write-Log {
param([string]$Message)
Add-Content -Path $logPath -Value "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - $Message"
}
try {
New-Item -ItemType Directory -Path $scriptDir -Force | Out-Null
New-Item -ItemType Directory -Path $outputFolder -Force | Out-Null
Write-Log "Script started."
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
# Get original filename from actual Microsoft Paint process only
$paintWindow = Get-Process |
Where-Object {
$_.ProcessName -eq "mspaint" -and
$_.MainWindowTitle -and
$_.MainWindowTitle.Trim().Length -gt 0
} |
Select-Object -First 1
$fileName = $null
if ($paintWindow) {
$title = $paintWindow.MainWindowTitle
Write-Log "Paint title: $title"
# Example Paint title: IMG_1234.jpg - Paint
$nameFromTitle = $title -replace "\s+-\s+Paint.*$", ""
$nameFromTitle = $nameFromTitle.Trim()
if ($nameFromTitle -and $nameFromTitle -notmatch "Untitled") {
$fileName = [System.IO.Path]::GetFileName($nameFromTitle)
}
}
if (-not $fileName) {
$timestamp = Get-Date -Format "yyyyMMdd_HHmmss"
$fileName = "paint_rotated_200w_$timestamp.jpg"
Write-Log "Could not detect original filename. Using fallback filename: $fileName"
}
…
user: is it possible to have a script similar to this, but it has one extra step where it trims either the left side or right side of the picture down to 2274 or 2273 pixels wide, then do everythign else your previous script does. is that possible?
assistant: Yes, that’s very possible. The clean way is to make a second Stream Deck button/script so your original 200px workflow stays untouched, and this new one does: crop width → rotate → resize to 200px wide → save with same filename → close Paint.
assistant: Yes. Make a **second script** so your original button stays working.
This version has two settings near the top:
```powershell
$cropTargetWidth = 2274
$trimSide = "right"
```
Meaning:
```text
"right" = cut off the right side, keep the left 2274 px
"left" = cut off the left side, keep the right 2274 px
```
For 2273 instead, change:
```powershell
$cropTargetWidth = 2273
```
## New PowerShell script
Save this as:
```text
C:\1\Paint-Crop-Rotate-Resize-Save.ps1
```
```powershell
$ErrorActionPreference = "Stop"
$scriptDir = "C:\1"
$logPath = Join-Path $scriptDir "paint-crop-resize-log.txt"
$outputFolder = "C:\Users\mcwlp\OneDrive\Desktop\WHITTENBURG BLUE 3523D 04H\PICS"
# Crop settings
$cropTargetWidth = 2274
$trimSide = "right" # "right" cuts off right side; "left" cuts off left side
function Write-Log {
param([string]$Message)
Add-Content -Path $logPath -Value "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - $Message"
}
try {
New-Item -ItemType Directory -Path $scriptDir -Force | Out-Null
New-Item -ItemType Directory -Path $outputFolder -Force | Out-Null
Write-Log "Script started."
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
# Get original filename from actual Microsoft Paint process only
$paintWindow = Get-Process |
Where-Object {
$_.ProcessName -eq "mspaint" -and
$_.MainWindowTitle -and
$_.MainWindowTitle.Trim().Length -gt 0
} |
Select-Object -First 1
$fileName = $null
if ($paintWindow) {
$title = $paintWindow.MainWindowTitle
Write-Log "Paint title: $title"
# Example Paint title: IMG_1234.jpg - Paint
$nameFromTitle = $title -replace "\s+-\s+Paint.*$", ""
$nameFromTitle = $nameFromTitle.Trim()
if ($nameFromTitle -and $nameFromTitle -notmatch "Untitled") {
$fileName = [System.IO.Path]::GetFileName($nameFromTitle)
}
}
if (-not $fileNam…
user: let's use $cropTargetWidth = 2273
and I want you to randomize like a coin toss to trim the left or right side. then I will use this on my second button.
assistant: Perfect — here is the **full second script** with:
- `2273` pixel crop width
- a **random coin toss** each time to trim either the **left** or **right** side
- then it:
- rotates 90° clockwise
- resizes to 200 px wide
- saves with the same filename into your `PICS` folder
- closes Paint
## Save this as
```text
C:\1\Paint-Crop-Rotate-Resize-Save.ps1
```
```powershell
$ErrorActionPreference = "Stop"
$scriptDir = "C:\1"
$logPath = Join-Path $scriptDir "paint-crop-resize-log.txt"
$outputFolder = "C:\Users\mcwlp\OneDrive\Desktop\WHITTENBURG BLUE 3523D 04H\PICS"
# Crop settings
$cropTargetWidth = 2273
function Write-Log {
param([string]$Message)
Add-Content -Path $logPath -Value "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - $Message"
}
try {
New-Item -ItemType Directory -Path $scriptDir -Force | Out-Null
New-Item -ItemType Directory -Path $outputFolder -Force | Out-Null
Write-Log "Script started."
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
# Get original filename from actual Microsoft Paint process only
$paintWindow = Get-Process |
Where-Object {
$_.ProcessName -eq "mspaint" -and
$_.MainWindowTitle -and
$_.MainWindowTitle.Trim().Length -gt 0
} |
Select-Object -First 1
$fileName = $null
if ($paintWindow) {
$title = $paintWindow.MainWindowTitle
Write-Log "Paint title: $title"
# Example Paint title: IMG_1234.jpg - Paint
$nameFromTitle = $title -replace "\s+-\s+Paint.*$", ""
$nameFromTitle = $nameFromTitle.Trim()
if ($nameFromTitle -and $nameFromTitle -notmatch "Untitled") {
$fileName = [System.IO.Path]::GetFileName($nameFromTitle)
}
}
if (-not $fileName) {
$timestamp = Get-Date -Format "yyyyMMdd_HHmmss"
$fileName = "paint_cropped_rotated_200w_$timestamp.jpg"
Write-Log "Could not detect original filename. Using fa…
user: I already have Paint-Rotate-Resize-Save.ps1 script file in this folder which I'm using with my streamdeck. amd i supposed to overwrite the whole thing? I was expecting we have a different filename for this stream deck button.
assistant: Correct — **do not overwrite** your working script.
Keep this existing file exactly as-is:
```text
C:\1\Paint-Rotate-Resize-Save.ps1
```
That is your original Stream Deck button.
For the second button, create a **new PowerShell script** with this filename:
```text
C:\1\Paint-Crop-Rotate-Resize-Save.ps1
```
Then create a **new CMD launcher** with this filename:
```text
C:\1\paint-crop-resize-button.cmd
```
That CMD launcher should contain:
```bat
@echo off
powershell.exe -NoProfile -ExecutionPolicy Bypass -STA -WindowStyle Hidden -File "C:\1\Paint-Crop-Rotate-Resize-Save.ps1"
```
Then your second Stream Deck button should point to:
```text
C:\1\paint-crop-resize-button.cmd
```
So your `C:\1` folder should have at least these files:
```text
C:\1\Paint-Rotate-Resize-Save.ps1 ← original button
C:\1\paint-resize-button.cmd ← original button launcher
C:\1\Paint-Crop-Rotate-Resize-Save.ps1 ← new crop/random button
C:\1\paint-crop-resize-button.cmd ← new crop/random button launcher
```
So yes, your expectation was right: **different filename, different Stream Deck button, original script untouched.**
user: after you made the first button for me yesterday. I started thinking of all kinds of things we can do.
Here is a list of some different things I'm trying to achieve:
1) There is gas monitoring software called Rig Rooster. I export the data, but it's in a plain text file.
I want to automatically convert text to columns/delimited/space
2) Another example of something I wonder it it is possible.
The MWD driller sends me an email with a LAS file attached. I normally have to open it in excel and convert text to columns/delimited/space.
Then I have to append the newer data from this file to another file called GAMMA.txt
it only has two columns, A and B. A is the depth and B is the gamma.
He sends this email every hour, I was just wondering if there is some kind of way we can automate this
assistant: This is exactly the right kind of thing to automate. The first Paint button proved the model: Stream Deck launches a small reliable script, and now we can apply that to drilling data, LAS files, gamma merges, and email attachments.
assistant: Yes — both of those are very automatable, and honestly they are better candidates for automation than the Paint resize job.
The big idea is: **stop using Excel as the converter**. Excel is just doing whitespace parsing. A script can do that faster and more reliably.
## 1. Rig Rooster plain text export → columns
Yes, we can make a Stream Deck button that does something like:
```text
Take latest Rig Rooster .txt export
Split rows by spaces/tabs
Clean up extra spacing
Save as CSV or tab-delimited TXT
Optionally open the result in Excel
```
So instead of opening Excel → Text to Columns → Delimited → Space, the script would produce something like:
```text
RigRooster_Converted.csv
```
or:
```text
RigRooster_Converted.txt
```
This is very doable if the export is consistently spaced.
The only thing I would want to see is a small sample of the Rig Rooster text file, because there are two common cases:
```text
Depth Gas C1 C2 C3
13500 120 85 12 3
```
versus messy fixed-width columns like:
```text
13500 120.5 85.2 12.1
13501 99.8 71.3 9.7
```
Both are solvable, but the script changes slightly.
## 2. MWD email LAS attachment → append new gamma to GAMMA.txt
Yes, this is also possible. This is the more valuable one.
The workflow would be:
```text
MWD sends LAS file every hour
Attachment lands in a folder
Script reads the LAS file
Script finds the depth column and gamma column
Script extracts only new rows
Script appends them to GAMMA.txt
Script avoids duplicate depths
```
Your `GAMMA.txt` would stay simple:
```text
13500 82
13501 84
13502 79
```
No Excel needed.
## The clean automation design I recommend
Use folders like this:
```text
C:\1\MWD_LAS_INBOX
C:\1\MWD_LAS_PROCESSED
C:\1\MWD_LOGS
C:\1\RigRooster
```
Then your actual target file could be wherever you already keep it, for example:
```text
C:\Users\mcwlp\OneDrive\Desktop\WHITTENBURG BLUE 3523D 04H\GAMMA.txt
```
The LAS autom…
user: actually, when I think about it, we probably don't even have to append the data. we can just use all the data from columns A and B
There are other columns in the LAS file but those are meaningless to us. We only use A and B
then on the second hand, I'm thinking. we can simply just process the LAS file and over write and rename or overwrite our GAMMA.txt file
There is additional challenge though. near the end of the LAS file there are cells that have -999.25
Those rows need to be stripped out the bottom section everytime I process the LAS file I receive.
I'll attach both files. so you can see what I mean.
assistant: This is a good simplification: instead of appending hourly, we can regenerate `GAMMA.txt` fresh from the newest LAS every time. I’ll inspect the LAS structure and your current `GAMMA.txt` format, then give you a Stream Deck-ready script.
Showing first 50 of 126 messages. View the full conversation at https://mcwai.org/ai-conversation/stream-deck-xl-button-to-rotate-and-resize-jpg