Skip to content

Instantly share code, notes, and snippets.

@pixelomer
Created August 19, 2025 06:20
Show Gist options
  • Select an option

  • Save pixelomer/fec0c1bfb1271f2f9bf5ee13d60c4f08 to your computer and use it in GitHub Desktop.

Select an option

Save pixelomer/fec0c1bfb1271f2f9bf5ee13d60c4f08 to your computer and use it in GitHub Desktop.
AutoHotkey script to automatically remove backgrounds from many images with Microsoft Paint on Windows 11
#Requires AutoHotkey v2.0
; Copyright (c) 2025 pixelomer
; All Rights Reserved.
Source := "C:\path\to\original\images\*.jpg"
Target := "C:\path\to\output\folder"
Loop Files, Source
{
; Determine output path
SavePath := Target "\" A_LoopFileName
SavePath := SubStr(SavePath, 1, -StrLen(A_LoopFileExt)-1) ".png"
if FileExist(SavePath)
{
; Don't overwrite existing images
continue
}
; Launch Paint
Run("mspaint.exe `"" A_LoopFileFullPath "`"")
Sleep(1000)
WinActivate("ahk_exe mspaint.exe")
; Copilot menu
Send("{LAlt}C")
Sleep(200)
; Remove background (Copilot)
Send("{LAlt}B")
Sleep(1000)
; Hide background for transparency
Send("{Ctrl down}{LShift down}H{Ctrl up}{LShift up}")
Sleep(200)
; Save as PNG
Send("{LAlt}F")
Sleep(200)
Send("A")
Sleep(200)
Send("P")
Sleep(1000)
; Respond to save dialog
Send("{Text}" SavePath "`n")
Sleep(1000)
; Close Paint
Send("{LAlt down}{F4 down}{F4 up}{LAlt up}")
Sleep(500)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment