A Python script that saves a clipboard (GTK) image to a file.

You can take a screen capture of the screen by pressing Ctrl + (Alt | Shift) + PrintScreen, but if you press Ctrl, the screen capture will be saved on the clipboard. (Usually you can press (Alt | Shift) + PrintScreen without pressing Ctrl to bring up a dialog and save it to a file.)

This time, save the image saved on the clipboard to a file with Python. By the way, it cannot be executed without GTK environment.

clip2img.py


#! /usr/bin/env python
# -*- coding: utf-8 -*-
 
import sys
import gtk
 
 
def save_clipimg(filename):
  clipboard = gtk.clipboard_get()
  image = clipboard.wait_for_image()
 
  if image is not None:
    image.save(filename, "png")
  else:
    print("No image in clipborad.")
 
def main():
  save_clipimg((sys.argv+["clipboard.png "])[1])
 
 
main()

Gist

Originally, I should use paint software quietly.

Recommended Posts

A Python script that saves a clipboard (GTK) image to a file.
A memorandum to run a python script in a bat file
Python script to create a JSON file from a CSV file
A Python script that reads a SQL file, executes BigQuery and saves the csv
[python] Change the image file name to a serial number
A python script that converts Oracle Database data to csv
Create a shell script to run the python file multiple times
A script that returns 0, 1 attached to the first Python prime number
I made a library that adds docstring to a Python stub file.
Script to create a Mac dictionary file
How to run a Maya Python script
Script python file
A Python script that automatically collects typical images using bing image search
Python script that outputs all records of Oracle table to CSV file
How to read a CSV file with Python 2/3
How to create a JSON file in Python
A script that retrieves tweets with Python, saves them in an external file, and performs morphological analysis.
"Python Kit" that calls a Python script from Swift
Export Python3 version OpenCV KeyPoint to a file
I want to write to a file with Python
A python script that draws a band diagram from the VASP output file EIGENVAL
Parse a JSON string written to a file in Python
Template of python script to read the contents of the file
I want to randomly sample a file in Python
What's in that variable (when running a Python script)
[Python] How to write a docstring that conforms to PEP8
[Python] A convenient library that converts kanji to hiragana
A Python script that crawls RSS in Azure Status and posts it to Hipchat
A python script that imports a dated csv file into BigQuery as a time partition table
Software that saves the set character string to the clipboard when you click the [Python] button
A python script that wants to use Mac startup / end time for attendance management
How to use NUITKA-Utilities hinted-compilation to easily create an executable file from a Python script
A road to intermediate Python
I made a script in Python to convert a text file for JSON (for vscode user snippet)
How to run a Python file at a Windows 10 command prompt
How to run a Python program from within a shell script
Change the standard output destination to a file in Python
Let's create a script that registers with Ideone.com in Python.
How to import a file anywhere you like in Python
Upload a file to Dropbox
Creating a Python script that supports the e-Stat API (ver.2)
A program that automatically resizes the iOS app icon to the required image size in Python
A Python script that goes from Google search to saving the Search results page at once
How to write a metaclass that supports both python2 and python3
[Python] How to output a pandas table to an excel file
A set of script files that do wordcloud in Python3
A Python script that allows you to check the status of the server from your browser
A Python script that compares the contents of two directories
I wrote a script that splits the image in two
[Python] A story that seemed to fall into a rounding trap
I tried to make a script that traces the tweets of a specific user on Twitter and saves the posted image at once
I want to use a wildcard that I want to shell with Python remove
I tried to convert a Python file to EXE (Recursion error supported)
How to pass arguments to a Python script in SPSS Modeler Batch
A story that struggled to handle the Python package of PocketSphinx
Process Splunk execution results using Python and save to a file
Conditional branch due to the existence of a shell script file
[Python] A memo that I tried to get started with asyncio
Try to extract a character string from an image with Python3
I wrote a function to load a Git extension script in Python
[Python] How to store a csv file as one-dimensional array data