Giter Site home page Giter Site logo

alexdelorenzo / screenshot Goto Github PK

View Code? Open in Web Editor NEW
166.0 4.0 13.0 53 KB

๐Ÿ“ธ Automate capturing screenshots of apps and windows on macOS

Home Page: https://alexdelorenzo.dev

License: GNU Affero General Public License v3.0

Python 100.00%
screenshot screencapture macosx mac osx quartz automated macos screenshots capture

screenshot's Introduction

๐Ÿ“ธ screenshot: Better macOS screenshots via the Terminal

screenshot is a command line utility that lets you specify an application name and window title in order to take a screenshot of a specific window.

Using screenshot, you can capture windows belonging to an application, or only an application's windows with certain titles.

Justification and Use Case

The macOS screencapture utility is not developer friendly.

To programmatically take a screenshot of an application, or a specific window, you must supply a window ID to screencapture. In order to find a window's window ID, you'll need call out to Quartz.

In newer versions of macOS, the screencapture utility improves the user experience slightly: you can run the command and then click on the window you'd like to capture.

However, that necessitates that the user clicks a window each time. You cannot include this as part of an automated pipeline.

To that end, I use this utility to automatically generate screenshots of web, mobile and desktop applications.

Example

Take a screenshot of the current Terminal window and view it with Preview.app:

open "`screenshot Terminal`"

Take a screenshot of the Pycharm application with the window title containing "screenshot":

screenshot Pycharm -t screenshot

Installation

You will need Python 3.6+. Please install it with brew or ports if you do not have it already.

PyPI

pip3 install screenshot

Github Source

Grab the source, run the following in the source dir:

pip3 install -r requirements.txt

then run

python3 setup.py install

Usage

screenshot --help

Usage: screenshot [OPTIONS] APPLICATION_NAME

Options:
  -w, --window_selection_options TEXT
                                  Options: all_windows, on_screen_only,
                                  above_window, below_window, include_window,
                                  exclude_desktop
                                  Default: exclude_desktop
                                  on_screen_only
  -t, --title TEXT                Title of window from APPLICATION_NAME to
                                  capture.
  -f, --filename TEXT             Filename to save the captured PNG as.
  -a, --all_windows               Capture all windows matching parameters.
  -o, --output TEXT               Image format to create, default is png
                                  (other options include pdf, jpg, tiff)
  -s, --shadow                    Capture the shadow of the window.
  --help                          Show this message and exit.

License

See LICENSE. Message me if you'd like to use this project with a different license.

screenshot's People

Contributors

alexdelorenzo avatar jtokash avatar thismachinechills avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

screenshot's Issues

Quiet screenshot

Hi, how can I take quiet screenshots? With screencapture it is possible by appending -x, so
I've tried to run screenshot -x APP_NAME but Error: no such option: -x is prompted

How to use screenshot on Mac OS X?

I got the following error on Mac OS X 10.15.6. Could anybody let me know how to fix it?

$ pip3 install screenshot
Requirement already satisfied: screenshot in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (1.0.1)
Requirement already satisfied: detect in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from screenshot) (2020.12.3)
Requirement already satisfied: click in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from screenshot) (7.0)
Requirement already satisfied: pyobjc-framework-Quartz in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from screenshot) (7.1)
Requirement already satisfied: pyobjc-framework-Cocoa>=7.1 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pyobjc-framework-Quartz->screenshot) (7.1)
Requirement already satisfied: pyobjc-core>=7.1 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pyobjc-framework-Quartz->screenshot) (7.1) 
$ screenshot Terminal
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/bin/screenshot", line 5, in <module>
    from screenshot.mac.capture import run
ModuleNotFoundError: No module named 'screenshot.mac'

unable to capture full screen windows

screenshot -t "Notes" "Notes" works great ๐Ÿ‘

However, when I put Notes into full screen and try again, I get :
Error: Window with parent Notes and title Notes not found.

How can I capture a window that's currently in full screen?

Add option to activate window before capture

If running screenshot interactively from the terminal, terminal will be the active application when the screenshot is taken rather than the application for the window being captured. An option to activate/raise the window of the application being captured would be useful.

Wrong version of PyObjC C API

Just tried to install and run, got this error.

shannon$ pip install screenshot
Collecting screenshot
  Downloading screenshot-1.0.0-py3-none-any.whl (5.3 kB)
Requirement already satisfied: pyobjc-framework-Quartz in ./opt/miniconda3/lib/python3.8/site-packages (from screenshot) (7.3)
Requirement already satisfied: click in ./opt/miniconda3/lib/python3.8/site-packages (from screenshot) (8.1.3)
Requirement already satisfied: pyobjc-core>=7.3 in ./opt/miniconda3/lib/python3.8/site-packages (from pyobjc-framework-Quartz->screenshot) (8.5)
Requirement already satisfied: pyobjc-framework-Cocoa>=7.3 in ./opt/miniconda3/lib/python3.8/site-packages (from pyobjc-framework-Quartz->screenshot) (8.5)
Installing collected packages: screenshot
Successfully installed screenshot-1.0.0
shannon$ screenshot -h
Traceback (most recent call last):
  File "/Users/shannon/opt/miniconda3/bin/screenshot", line 5, in <module>
    from screenshot.screencapture import run
  File "/Users/shannon/opt/miniconda3/lib/python3.8/site-packages/screenshot/screencapture.py", line 9, in <module>
    from .get_window_id import gen_window_ids, WINDOW_OPTIONS, USER_OPTS_STR
  File "/Users/shannon/opt/miniconda3/lib/python3.8/site-packages/screenshot/get_window_id.py", line 4, in <module>
    from Quartz import CGWindowListCopyWindowInfo, kCGWindowListExcludeDesktopElements, kCGNullWindowID, \
  File "/Users/shannon/opt/miniconda3/lib/python3.8/site-packages/Quartz/__init__.py", line 110, in <module>
    _load()
  File "/Users/shannon/opt/miniconda3/lib/python3.8/site-packages/Quartz/__init__.py", line 28, in _load
    from Quartz import CoreGraphics as m
  File "/Users/shannon/opt/miniconda3/lib/python3.8/site-packages/Quartz/CoreGraphics/__init__.py", line 147, in <module>
    _load(mod)
  File "/Users/shannon/opt/miniconda3/lib/python3.8/site-packages/Quartz/CoreGraphics/__init__.py", line 55, in _load
    import Quartz.CoreGraphics._callbacks as m
RuntimeError: Wrong version of PyObjC C API (got 23, expected 21)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.