2020-09-01 11:17:43 +02:00
|
|
|
;;; scrot.el --- Screenshot functions -*- lexical-binding: t -*-
|
|
|
|
|
2020-01-16 20:16:56 +01:00
|
|
|
;; Author: William Carroll <wpcarro@gmail.com>
|
2020-09-01 11:17:43 +02:00
|
|
|
;; Version: 0.0.1
|
|
|
|
;; URL: https://git.wpcarro.dev/wpcarro/briefcase
|
|
|
|
;; Package-Requires: ((emacs "24"))
|
2020-01-16 20:16:56 +01:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
;; scrot is a Linux utility for taking screenshots.
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; Dependencies
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
(require 'f)
|
|
|
|
(require 'string)
|
|
|
|
(require 'ts)
|
|
|
|
(require 'clipboard)
|
|
|
|
(require 'kbd)
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; Library
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2020-09-01 11:17:43 +02:00
|
|
|
(defconst scrot-screenshot-directory "~/Downloads"
|
2020-01-16 20:16:56 +01:00
|
|
|
"The default directory for screenshot outputs.")
|
|
|
|
|
2020-09-01 11:17:43 +02:00
|
|
|
(defconst scrot-path-to-executable "/usr/bin/scrot"
|
2020-01-16 20:16:56 +01:00
|
|
|
"Path to the scrot executable.")
|
|
|
|
|
2020-09-01 11:17:43 +02:00
|
|
|
(defconst scrot-output-format "screenshot_%H:%M:%S_%Y-%m-%d.png"
|
2020-01-16 20:16:56 +01:00
|
|
|
"The format string for the output screenshot file.
|
|
|
|
See scrot's man page for more information.")
|
|
|
|
|
2020-09-01 11:17:43 +02:00
|
|
|
(defun scrot-copy-image (path)
|
2020-01-16 20:16:56 +01:00
|
|
|
"Use xclip to copy the image at PATH to the clipboard.
|
|
|
|
This currently only works for PNG files because that's what I'm outputting"
|
|
|
|
(call-process "xclip" nil nil nil
|
|
|
|
"-selection" "clipboard" "-t" "image/png" path)
|
2020-09-01 00:28:47 +02:00
|
|
|
(message (string-format "[scrot.el] Image copied to clipboard!")))
|
2020-01-16 20:16:56 +01:00
|
|
|
|
2020-09-01 11:17:43 +02:00
|
|
|
(defmacro scrot-call (&rest args)
|
2020-01-16 20:16:56 +01:00
|
|
|
"Call scrot with ARGS."
|
2020-09-01 11:17:43 +02:00
|
|
|
`(call-process ,scrot-path-to-executable nil nil nil ,@args))
|
2020-01-16 20:16:56 +01:00
|
|
|
|
2020-09-01 11:17:43 +02:00
|
|
|
(defun scrot-fullscreen ()
|
2020-01-16 20:16:56 +01:00
|
|
|
"Screenshot the entire screen."
|
|
|
|
(interactive)
|
2020-09-01 11:17:43 +02:00
|
|
|
(let ((screenshot-path (f-join scrot-screenshot-directory
|
|
|
|
(ts-format scrot-output-format (ts-now)))))
|
|
|
|
(scrot-call screenshot-path)
|
|
|
|
(scrot-copy-image screenshot-path)))
|
2020-01-16 20:16:56 +01:00
|
|
|
|
2020-09-01 11:17:43 +02:00
|
|
|
(defun scrot-select ()
|
2020-01-16 20:16:56 +01:00
|
|
|
"Click-and-drag to screenshot a region.
|
|
|
|
The output path is copied to the user's clipboard."
|
|
|
|
(interactive)
|
2020-09-01 11:17:43 +02:00
|
|
|
(let ((screenshot-path (f-join scrot-screenshot-directory
|
|
|
|
(ts-format scrot-output-format (ts-now)))))
|
|
|
|
(scrot-call "--select" screenshot-path)
|
|
|
|
(scrot-copy-image screenshot-path)))
|
2020-01-16 20:16:56 +01:00
|
|
|
|
|
|
|
(provide 'scrot)
|
|
|
|
;;; scrot.el ends here
|