The Usage of Linux scrot Program

Linux scrot 程式的用法

【摘要】scrot 是指令行的螢幕擷取程式。本文介紹在不同場合的使用方法,包括在虛擬終端機、shell 程式檔、.desktop 檔、fbpanel 的 launchbar、FluxBox 的 keys 檔等,並列舉了十個範例。


【目錄】

    【前言
    【各場合的用法
    【範例
    【後語
    【附錄 scrot Manual

【前言】

一、scrot 是指令行的螢幕擷取程式。man scrot(見附錄)雖有說明,但未提及在不同狀況的使用差異。本文列出在虛擬終端機、shell 程式檔、.desktop 檔、fbpanel 的 launchbar、FluxBox 的 keys 檔中的不同用法。


二、四年前曾發表過「Linux scrot 的用法」,近日重新檢視更新並添加範例,分享於此。


三、本例是在自組的 FluxBox Debian GNU/Linux 10 系統中測試,發現了一些現象:

  • 截圖可以是 png 和 jpg 格式,但不能做出 gif 檔。
  • 選項 -q/--quality 只對 jpg 格式有效,對 png 無效。
  • 使用選項 -s/--select 時,不能按任何按鍵。
  • -s 選取某視窗時,其上層的其它視窗也會被截取。
  • 最方便的方式是放在 panel/toolbar/launch-bar 中,只要點選其中設定的圖示即可執行。

【各場合的用法】

以下列出的指令都在自製的 Debian 10 測試過,應該都可以使用。比較單純的應該是各類的第一個,直接給路徑。請注意單引號和雙引號的差異,以及 $% 的 escaped。

一、虛擬終端機 / shell 指令檔

scrot $HOME/Pictures/%m%d-%H%M%S.png
scrot %m%d-%H%M%S.png -e 'mv $f $$HOME/Pictures'
scrot %m%d-%H%M%S.png -e "mv \$f $HOME/Pictures"

二、.desktop 檔

scrot /home/USER/Pictures/%%m%%d-%%H%%M%%S.png
scrot %%m%%d-%%H%%M%%S.png -e 'mv $f /home/USER/Pictures'
scrot %%m%%d-%%H%%M%%S.png -e 'mv $f $$HOME/Pictures'
scrot %%m%%d-%%H%%M%%S.png -e "mv $f $$HOME/Pictures"
scrot %%m%%d-%%H%%M%%S.png -e "mv $f \\\$HOME/Pictures"
scrot %%m%%d-%%H%%M%%S.png -e "mv \$f $$HOME/Pictures"
scrot %%m%%d-%%H%%M%%S.png -e "mv \$f \\\$HOME/Pictures"

在檔案管理員中,用鼠標雙點此檔,或選了此檔再按 [Enter],皆可正常使用。將此檔拖放至桌面,也可使用。但 fbpanel 中的 systemmenu,則不能用。


三、fbpanel 的 launchbar

scrot /home/USER/Pictures/%m%d-%H%M%S.png
scrot %m%d-%H%M%S.png -e 'mv $f /home/USER/Pictures'
scrot %m%d-%H%M%S.png -e 'mv $f $$HOME/Pictures'
scrot %m%d-%H%M%S.png -e 'mv \\$f \$HOME/Pictures'
scrot %m%d-%H%M%S.png -e "mv $f $$HOME/Pictures"
scrot %m%d-%H%M%S.png -e "mv \$f $$HOME/Pictures"
scrot %m%d-%H%M%S.png -e "mv $f \\$HOME/Pictures"
scrot %m%d-%H%M%S.png -e "mv $f \\\$HOME/Pictures"

四、FluxBox 的 keys 檔

scrot $HOME/Pictures/%m%d-%H%M%S.png
scrot %m%d-%H%M%S.png -e 'mv $f $$HOME/Pictures'
scrot %m%d-%H%M%S.png -e "mv \$f $HOME/Pictures"

【範例】

以下是較常用的範例,指令以虛擬終端機的狀況為例:

㈠ 直接取全螢幕

scrot $HOME/Pictures/%m%d-%H%M%S.png

㈡ 3 秒後截取全螢幕,這 3 秒可改變螢幕狀況

scrot -d3 $HOME/Pictures/%m%d-%H%M%S.png

㈢ 截取一矩形區域

scrot -s $HOME/Pictures/%m%d-%H%M%S.png

㈣ 截取一矩形區域並縮小

scrot -st50 $HOME/Pictures/%m%d-%H%M%S.png

㈤ 點選某視窗後,延遲 3 秒截取,這 3 秒可將目標視窗移到最上層

scrot -sd3 $HOME/Pictures/%m%d-%H%M%S.png

㈥ 選取某視窗及其邊框,延遲的 3 秒可將目標視窗移到最上層

scrot -bsd3 $HOME/Pictures/%m%d-%H%M%S.png

㈦ 選取某視窗及其邊框製成縮圖,延遲的 3 秒可將目標視窗移到最上層

scrot -bst50 -d3 $HOME/Pictures/%m%d-%H%M%S.png
scrot -bst50 -d3 %m%d-%H%M%S.png -e 'mv -t $$HOME/Pictures $f $$(basename $f .png)-thumb.png'

㈧ 截取 focused 視窗及其邊框,延遲的 3 秒可將目標視窗移到最上層

scrot -bud3 $HOME/Pictures/%m%d-%H%M%S.png

㈨ 截取以螢幕座標 (100, 200) 為左上角,寬 400 px,高 300 px 的矩形區域

scrot -a100,200,400,300 $HOME/Pictures/%m%d-%H%M%S.png

㈩ 截取一矩形區域並用 ImageMagick 轉為灰階及 gif 格式

scrot -s %m%d-%H%M%S.png -e 'convert $f -colorspace Gray $$(basename $f .png).gif'

【後語】

一、不同的選項雖然可以截取不同的畫面,但有優先順序;也就是說,若同時有多項,只有一個有效。順序為:
-u/--focused > -s/--select > -a/--autoselect


二、大部分的場合都有以下現象:

  • -u/--focused,則 -a-s 無效,-b-d-q-t 有效。
  • -s/--select, 則 -a 無效,-b-d-q-t 有效。
  • -a/--autoselect,則 -d 無效,-q-t 有效,-b 無意義。

唯一例外是在 FluxBox 的 keys 檔中設成快捷鍵時,-s 選項無效。


【附錄 scrot Manual】

scrot(1)              command line screen capture utility             scrot(1)
 
NAME
       scrot - command line screen capture utility
 
SYNOPSIS
       scrot [options] [file]
 
DESCRIPTION
       scrot (SCReenshOT) is a simple command line screen capture utility that
       uses imlib2 to grab and save images. Multiple image  formats  are  sup‐
       ported through imlib2's dynamic saver modules.
 
       Some features of the scrot:
 
              •  support to multiple image formats (JPG, PNG, GIF, etc.).
 
              •  optimization of the screen shots image quality.
 
              •  capture a specific window or a rectangular area on the screen
                 with the help of switch.
 
       scrot also can be used to monitor a desktop PC in admin absent and reg‐
       ister unwanted activities.
 
OPTIONS
       -h, --help
              Display help output and exit.
 
       -v, --version
              Output version information and exit.
 
       -a, --autoselect
              Non-interactively choose a rectangle of x,y,w,h.
 
       -b, --border
              When selecting a window, grab wm border too.
 
       -c, --count
              Display a countdown when used with delay.
 
       -d, --delay NUM
              Wait NUM seconds before taking a shot.
 
       -e, --exec APP
              Exec APP on the saved image.
 
       -q, --quality NUM
              Image   quality (1-100) high value means high size, low compres‐
              sion. Default: 75. (Effect differs depending on file format cho‐
              sen).
 
       -m, --multidisp
              For multiple heads, grab shot from each and join them together.
 
       -s, --select
              Interactively select a window or rectangle with the mouse.
 
       -u, --focused
              Use the currently focused window.
 
       -t, --thumb NUM
              Generate  thumbnail  too.  NUM is the percentage of the original
              size for the thumbnail to be.
 
       -z, --silent
              Prevent beeping.
 
SPECIAL STRINGS
       Both the --exec and filename parameters can take format specifiers that
       are  expanded  by scrot when encountered. There are two types of format
       specifier.  Characters preceded by  a  '%'  are  interpreted  by  strf‐
       time(2).  See  man  strftime for examples. These options may be used to
       refer to the current date and time. The second  kind  are  internal  to
       scrot and are prefixed by '$' The following specifiers are recognised:
 
           $f  image path/filename (ignored when used in the filename)
           $n  image name (ignored when used in the filename)
           $s  image size (bytes) (ignored when used in the filename)
           $p  image pixel size
           $w  image width
           $h  image height
           $t  image format
           $$  print a literal '$'
           \n  print a newline (ignored when used in the filename)
 
EXAMPLE
       scrot '%Y-%m-%d_$wx$h.png' -e 'mv $f ~/shots/'
              This    would    create    a    file   called   something   like
              2000-10-30_2560x1024.png and move it to your shots directory.
 
AUTHOR
       scrot was originally developed by Tom Gilbert under MIT-advertising li‐
       cense.
 
       Currently,   source   code   and   newer   versions  are  available  at
       https://github.com/resurrecting-open-source-projects/scrot
 
scrot-0.9                        12 Feb. 2019                         scrot(1)

發表留言