help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Screenshots, frame shots straight from Emacs


From: Emanuel Berg
Subject: Re: Screenshots, frame shots straight from Emacs
Date: Fri, 02 Jul 2021 17:34:15 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Jean Louis wrote:

> (defvar frameshot-directory "~/Media/Pictures/Screenshots/"
>   "Default directory for frame shots")
>
> (defvar frameshot-format 'png
>   "Default frame shot format")

What's with all the global vars...

> (defun frameshot ()
>   "Save Emacs frame as frame shot.
> Directory is determined by variable `frameshot-directory' and if
> not defined, it will be saved in the `$HOME' directory."
>   (interactive)
>   (let* ((image (x-export-frames nil (or frameshot-format 'png)))
>        (base-directory (or frameshot-directory (getenv "HOME")))
>        (directory (concat (file-name-as-directory base-directory) 
> (format-time-string "%Y/%m/%Y-%m-%d/")))
>        (file (concat directory (format-time-string "Screenshot-%Y-%m-%d-%T.") 
> (symbol-name frameshot-format))))
>     (make-directory directory t)
>     (with-temp-file file
>       (insert image))
>     (find-file directory)
>     (message "Frame shot saved as `%s'" file)))

OK, cool.

This is what I do outside of Emacs (it can be used for Emacs
as well, if the VT is specified) - number 1, tty1 - or, again,
if invoked from Emacs with the designated defun.

The Linux VT / X issue, again, but here not really a problem
since so easy on both accounts. Or so good provided already,
maybe I should say.

#! /bin/zsh
#
# this file:
#   http://user.it.uu.se/~embe8573/conf/.zsh/dump
#   https://dataswamp.org/~incal/conf/.zsh/dump

last-arg () {
    echo ${@:${#@}}
}

dump-vt () {
    local vt=$1
    local file=$(last-arg $@).png # so it'll also work when $# = 1
    case $# in
        (1) fbgrab             $file ;;
        (2) sudo fbgrab -c $vt $file &&
            sudo chown $USER   $file &&
            sudo chgrp $USER   $file ;;
    esac
}
alias dumpvt=dump-vt

dump-x () {
    local name=$1
    local file=${name}.png
    local win_name=$2
    case $# in
        (1) gnome-screenshot -d 5  -f $file ;;
        (2) wmctrl -a $win_name             &&
            gnome-screenshot -w -B -f $file ;;
    esac 2> /dev/null
}

dump () {
    [[ $DISPLAY ]] && dump-x $@ || dump-vt $@
}

and from Emacs:

;;; -*- lexical-binding: t -*-
;;;
;;; this file:
;;;   http://user.it.uu.se/~embe8573/emacs-init/vt.el
;;;   https://dataswamp.org/~incal/emacs-init/vt.el

(defun dump (name)
  (interactive "sname: ")
  (message nil)
  (let ((file (format "~/%s.png" name)))
    (shell-command (format "fbgrab %s" file)) ))

-- 
underground experts united
https://dataswamp.org/~incal




reply via email to

[Prev in Thread] Current Thread [Next in Thread]