| 1 | import subprocess |
| 2 | from os.path import join |
| 3 | from plyer.facades import Screenshot |
| 4 | from plyer.utils import whereis_exe |
| 5 | from plyer.platforms.macosx.storagepath import OSXStoragePath |
| 6 | |
| 7 | |
| 8 | class OSXScreenshot(Screenshot): |
| 9 | def __init__(self, file_path=None): |
| 10 | default_path = join( |
| 11 | OSXStoragePath().get_pictures_dir().replace('file://', ''), |
| 12 | 'screenshot.png' |
| 13 | ) |
| 14 | super().__init__(file_path or default_path) |
| 15 | |
| 16 | def _capture(self): |
| 17 | subprocess.call([ |
| 18 | 'screencapture', |
| 19 | self.file_path |
| 20 | ]) |
| 21 | |
| 22 | |
| 23 | def instance(): |
| 24 | if whereis_exe('screencapture'): |
| 25 | return OSXScreenshot() |
| 26 | else: |
| 27 | return Screenshot() |