37 lines
1.5 KiB
Lua
37 lines
1.5 KiB
Lua
|
|
-- Capture full screen → save PNG under ~/Pictures/Screenshots/jarvis-YYYYMMDD-HHMMSS.png
|
|||
|
|
local t = jarvis.context.time
|
|||
|
|
local stamp = string.format("%04d%02d%02d-%02d%02d%02d",
|
|||
|
|
t.year, t.month, t.day, t.hour, t.minute, t.second or 0)
|
|||
|
|
|
|||
|
|
local userprofile = jarvis.system.env("USERPROFILE") or "C:\\Users\\Public"
|
|||
|
|
local dir = userprofile .. "\\Pictures\\Screenshots"
|
|||
|
|
local path = string.format("%s\\jarvis-%s.png", dir, stamp)
|
|||
|
|
|
|||
|
|
-- Ensure dir exists
|
|||
|
|
jarvis.fs.mkdir(dir)
|
|||
|
|
|
|||
|
|
local escaped = path:gsub("'", "''")
|
|||
|
|
local ps = string.format([[
|
|||
|
|
Add-Type -AssemblyName System.Windows.Forms
|
|||
|
|
Add-Type -AssemblyName System.Drawing
|
|||
|
|
$bounds = [System.Windows.Forms.Screen]::PrimaryScreen.Bounds
|
|||
|
|
$bmp = New-Object System.Drawing.Bitmap $bounds.Width, $bounds.Height
|
|||
|
|
$g = [System.Drawing.Graphics]::FromImage($bmp)
|
|||
|
|
$g.CopyFromScreen($bounds.Location, [System.Drawing.Point]::Empty, $bounds.Size)
|
|||
|
|
$bmp.Save('%s', [System.Drawing.Imaging.ImageFormat]::Png)
|
|||
|
|
$g.Dispose(); $bmp.Dispose()
|
|||
|
|
]], escaped)
|
|||
|
|
|
|||
|
|
local res = jarvis.system.exec(string.format(
|
|||
|
|
'powershell -NoProfile -ExecutionPolicy Bypass -Command "%s"',
|
|||
|
|
ps:gsub('"', '\\"'):gsub("\r?\n", "; ")
|
|||
|
|
))
|
|||
|
|
|
|||
|
|
if not res.success then
|
|||
|
|
jarvis.log("warn", "screenshot to file failed: " .. tostring(res.stderr):sub(1, 200))
|
|||
|
|
return jarvis.cmd.error("Не получилось сохранить скриншот.")
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
jarvis.system.notify("Скриншот", path)
|
|||
|
|
return jarvis.cmd.ok("Скриншот сохранён в папку Скриншоты.")
|