--GrabBox est inscored avec succès, mais le fichier image n'est pas enregistré dans Dropbox même si je prends une capture avec ** Shift + Cmd + 4 **
――Si vous pouvez déplacer l'image vers le répertoire spécifié de Dropbox après avoir pris la capture, c'est bien car c'est le même qu'avant.
Le contenu du script ressemble à ceci
move2dropbox.py
# -*- coding: utf-8 -*-
import time
import os
import uuid
import shutil
import subprocess
from PIL import Image
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
here = os.path.abspath(os.path.dirname(__file__))
HOME_DIR = os.path.expanduser('~')
SCREENSHOT_DIR = os.path.join(here, 'screenshot')
DROPBOX_DIR = os.path.join(HOME_DIR, 'Dropbox', 'App', 'GrabBox')
DROPBOX_URL = 'https://dl.dropboxusercontent.com/spa/xxxxxxxxx/'
CMD_LOCATION = 'defaults write com.apple.screencapture location {}'.format(SCREENSHOT_DIR)  # NOQA
CMD_NAME = 'defaults write com.apple.screencapture name "grabox"'
CMD_KILLALL = 'killall SystemUIServer'
def resize_for_retina(imgfile):
    img = Image.open(imgfile)
    resized = img.resize([int(0.5 * s) for s in img.size])
    resized.save(imgfile)
class MyHandler(FileSystemEventHandler):
    def on_created(self, event):
        for img in os.listdir(SCREENSHOT_DIR):
            if not img.endswith('.png'):
                continue
            new_img = '{}.png'.format(uuid.uuid4().hex)
            resize_for_retina(os.path.join(SCREENSHOT_DIR, img))
            shutil.move(
                os.path.join(SCREENSHOT_DIR, img),
                os.path.join(DROPBOX_DIR, new_img)
            )
            subprocess.call(
                'echo "{}" | pbcopy'.format(DROPBOX_URL + new_img),
                shell=True
            )
if __name__ == "__main__":
    if not os.path.exists(SCREENSHOT_DIR):
        os.makedirs(SCREENSHOT_DIR)
    subprocess.call(CMD_LOCATION, shell=True)
    subprocess.call(CMD_NAME, shell=True)
    subprocess.call(CMD_KILLALL, shell=True)
    observer = Observer()
    observer.schedule(MyHandler(), path=SCREENSHOT_DIR, recursive=False)
    observer.start()
    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        observer.stop()
    observer.join()
Enfin, créez un script shell qui frappe ce script en arrière-plan
move2dropbox.command
nohup python /path/to/move2dropbox.py > /dev/null 2>&1 &
** Ajoutez l'extension ".command" ** et enregistrez-la dans ** "Environnement système> Utilisateurs et groupes> Éléments de connexion" **

Désormais, lorsque vous vous connectez, le script de surveillance ci-dessus sera exécuté sans autorisation.
――Veuillez nous indiquer votre outil de capture recommandé dès maintenant (urgent)
Liste des recommandations
fin
Recommended Posts