25 lines
1.1 KiB
Lua
25 lines
1.1 KiB
Lua
|
|
local ts = jarvis.context.time.year .. jarvis.context.time.month .. jarvis.context.time.day
|
||
|
|
.. "_" .. jarvis.context.time.hour .. jarvis.context.time.minute .. jarvis.context.time.second
|
||
|
|
|
||
|
|
local userprofile = jarvis.system.env("USERPROFILE") or "C:\\Users\\Public"
|
||
|
|
local target = userprofile .. "\\Pictures\\jarvis_screenshot_" .. ts .. ".png"
|
||
|
|
|
||
|
|
local ps = string.format(
|
||
|
|
[[Add-Type -AssemblyName System.Windows.Forms,System.Drawing; $b=[System.Windows.Forms.Screen]::PrimaryScreen.Bounds; $bmp=New-Object Drawing.Bitmap $b.Width,$b.Height; $g=[Drawing.Graphics]::FromImage($bmp); $g.CopyFromScreen($b.Location,[Drawing.Point]::Empty,$b.Size); $bmp.Save('%s'); $g.Dispose(); $bmp.Dispose()]],
|
||
|
|
target:gsub("\\", "\\\\")
|
||
|
|
)
|
||
|
|
|
||
|
|
local cmd = string.format('powershell -NoProfile -ExecutionPolicy Bypass -Command "%s"', ps:gsub('"', '\\"'))
|
||
|
|
local res = jarvis.system.exec(cmd)
|
||
|
|
|
||
|
|
if res.success then
|
||
|
|
jarvis.log("info", "screenshot saved to " .. target)
|
||
|
|
jarvis.system.notify("Скриншот", target)
|
||
|
|
jarvis.audio.play_ok()
|
||
|
|
else
|
||
|
|
jarvis.log("error", "screenshot failed: " .. tostring(res.stderr))
|
||
|
|
jarvis.audio.play_error()
|
||
|
|
end
|
||
|
|
|
||
|
|
return { chain = false }
|