HOWTO: Take a screenshot from the command line
asked 2014-04-17 16:55:32 +0200
This post is a wiki. Anyone with karma >75 is welcome to improve it.
There are a couple of apps available on the Jolla store that will let you take screenshots via the interface, but occasionally you may want/need to capture the screen from the command line, particularly over SSH. The easiest way to do it is to use dbus to send a message to lipstick, the UX manager. It should work on both SailfishOS and Nemomobile, and on all devices.
Here are ways to do it on the command-line, over SSH or to be included in a shell script:
Using dbus-send
dbus-send --session --print-reply --dest=org.nemomobile.lipstick /org/nemomobile/lipstick/screenshot org.nemomobile.lipstick.saveScreenshot string:"/home/nemo/Pictures/Screenshot-$(date +%y-%m-%d-%H-%M-%S).png"
Using qdbus (from the qt5-qttools-qdbus package)
/usr/lib/qt5/bin/qdbus org.nemomobile.lipstick /org/nemomobile/lipstick/screenshot org.nemomobile.lipstick.saveScreenshot "/home/nemo/Pictures/Screenshot-$(date +%y-%m-%d-%H-%M-%S).png"
Using grabscreen
grabscreen "/home/nemo/Pictures/Screenshot-$(date +%y-%m-%d-%H-%M-%S).png"
The code-snippet below shows how you'd also achieve the same in Qt directly:
QDBusInterface *iface = new QDBusInterface("org.nemomobile.lipstick",
"/org/nemomobile/lipstick/screenshot",
"org.nemomobile.lipstick",
QDBusConnection::sessionBus(),
this);
iface->call(QDBus::NoBlock, "saveScreenshot", QString("/home/nemo/Pictures/Screenshot-%1.png").arg(QDateTime::currentDateTime().toString("yy-MM-dd-hh-mm-ss")));
You can also try
grabscreen --help
to see if this command is available on your Jolla. It takes PNG images, which may not display in Gallery but shouldxdg-open name.png
(by default) in your browser./usr/bin/grabscreen [/path/to/snapshot.png]
The limits to its versatility may be its independence (or not) of dbus and capturing a PNG whose properties are predefined by the command, apparently not user-tailorable. Correct me, I'm probably assuming too much by obvious appearance and oversimplifying undocumented tooling, or a describing a tool whose documentation I have not seen.
rdmo ( 2015-04-01 08:17:18 +0200 )editgrabscreen tool is part of jolla-developer-mode and can't be used in applications because of that. And it using same dbus method for capturing.
coderus ( 2015-04-01 12:38:04 +0200 )edit(@coderus: Jolly good. On-device CLI scripts are my interest at this point.)
rdmo ( 2015-04-01 12:59:26 +0200 )edit@rdmo & @coderus
via SSH;
$
sleep 10 && grabscreen
You now have just 10 seconds to get to the screen you want a shot of - grab goes straight to main gallery.
Simpler than all the above, no?, or am I missing something here?
Spam Hunter ( 2016-03-03 14:41:17 +0200 )editgrabscreen doing same dbus call internally :)
coderus ( 2016-03-03 15:16:02 +0200 )edit