Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save SMUsamaShah/6a28d25f3dac166126aaafa9fb123ddc to your computer and use it in GitHub Desktop.
Save SMUsamaShah/6a28d25f3dac166126aaafa9fb123ddc to your computer and use it in GitHub Desktop.
AutoHotkey V2 Script to download and set wallpaper using Flux Schnell model via segmind.com API
#Requires AutoHotkey v2.0
; Main function
Main() {
api_key := "YOUR_API_KEY_HERE" ; Replace with your actual API key
url := "https://api.segmind.com/v1/flux-schnell"
jsonData := GetJsonData()
;MsgBox("Debug input json: " . jsonData)
;return
try {
response := SendHttpRequest(url, api_key, jsonData)
if (response.Status == 200) {
filePath := SaveResponseToFile(response.ResponseBody)
SetWallpaper(filePath)
MsgBox("Wallpaper set successfully!")
} else {
MsgBox("Error: " . response.Status . " - " . response.StatusText . "`nResponse: " . response.ResponseText)
}
} catch as err {
MsgBox("Error: " . err.Message)
}
}
; Function to get JSON data
GetJsonData() {
randomSeed := Random(1, 999999999)
jsonTemplate := '
(
{
"prompt": "wide landscape wallpaper, a pathway, photorealistic ghibli style painting",
"steps": 4,
"seed": {1},
"sampler_name": "euler",
"scheduler": "normal",
"samples": 1,
"width": 1920,
"height": 1080,
"denoise": 1
}
)'
return Format(jsonTemplate, randomSeed)
}
; Function to send HTTP request
SendHttpRequest(url, api_key, jsonData) {
whr := ComObject("WinHttp.WinHttpRequest.5.1")
whr.SetTimeouts(0, 60000, 30000, 60000) ; Increase timeouts (connection, send, receive)
whr.Open("POST", url, true)
whr.SetRequestHeader("Content-Type", "application/json")
whr.SetRequestHeader("x-api-key", api_key)
whr.Send(jsonData)
whr.WaitForResponse()
return whr
}
; Function to save response to file
SaveResponseToFile(responseBody) {
; Create a folder to store wallpapers if it doesn't exist
wallpaperFolder := A_ScriptDir . "\Wallpapers"
if !DirExist(wallpaperFolder)
DirCreate(wallpaperFolder)
; Generate timestamp
timestamp := FormatTime(, "yyyyMMdd_HHmmss")
; Create file path with timestamp
filePath := wallpaperFolder . "\wallpaper_" . timestamp . ".jpg"
adoStream := ComObject("ADODB.Stream")
adoStream.Type := 1 ; Binary
adoStream.Open()
adoStream.Write(responseBody)
adoStream.SaveToFile(filePath, 2) ; 2 = overwrite
adoStream.Close()
return filePath
}
; Function to set wallpaper
SetWallpaper(imagePath) {
DllCall("SystemParametersInfo", "UInt", 0x14, "UInt", 0, "Str", imagePath, "UInt", 2)
}
; Run the main function
Main()
@SMUsamaShah
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment