LoginSignup
5
5

More than 5 years have passed since last update.

クリップボード(GTK)のイメージをファイルに保存する Python スクリプト。

Posted at

Ctrl+(Alt|Shift)+PrintScreen とかすると画面のスクリーンキャプチャが取れるわけですが、 Ctrl を押しているとスクリーンキャプチャはクリップボード上に保存されます。
(通常は Ctrl を押さずに (Alt|Shift)+PrintScreen とすることでダイアログが出てきてファイルに保存できると思います。)

今回はクリップボード上に保存してしまった画像を Python でファイルに保存します。ちなみにGTK環境がないと実行できません。

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

本来はおとなしくペイントソフト使えばいいんですけども。

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5