Created
October 31, 2015 18:56
-
-
Save daeyun/03721f95b7b11da463de to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" Take a screenshot, save to Dropbox, and copy link to clipboard. | |
Install imagemagick, xsel, and | |
sudo pip3 install sh docopt | |
Usage: screenshot.py [<delay>] | |
""" | |
import sh | |
import time | |
import os | |
import random | |
import string | |
from docopt import docopt | |
outdir = '/home/daeyun/Dropbox/Public/screenshots/' | |
dropbox_uid = '24134038' | |
def scrot(fullpath, delay=None): | |
scrot_args = ['-s', '-q', '100', fullpath] | |
if delay is not None: | |
scrot_args = ['-d', int(delay), '-c'] + scrot_args | |
sh.scrot(scrot_args) | |
def imagemagick(fullpath): | |
os.system("import {}".format(fullpath)) | |
def main(args): | |
if not os.path.exists(outdir): | |
os.makedirs(outdir) | |
# milliseconds | |
timestamp = int(time.time()*1000) | |
randstr = ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(7)) | |
filename = '{}-{}.png'.format("{:x}".format(timestamp).upper(), randstr) | |
fullpath = os.path.join(outdir, filename) | |
imagemagick(fullpath) | |
public_url = 'https://dl.dropboxusercontent.com/u/{}/screenshots/{}'.format(dropbox_uid, filename) | |
sh.xsel('-p', _in=public_url) | |
sh.xsel('-b', _in=public_url) | |
if __name__ == '__main__': | |
main(docopt(__doc__)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment