GrabBox didn't work on Sierra

Overview

--I still use a capture tool called GrabBox on my Mac (http://d.hatena.ne.jp/tell-k/20110523/1306166332) --When I Sierra the OS, it stopped working. (It's a mystery whether it's really Sierra's fault) Sad ――For the time being, I made a note because I made a quick response.

Status

--GrabBox is successfully inscored, but the image file is not saved in Dropbox even if I take a capture with ** Shift + Cmd + 4 ** --I was able to confirm that if you put the image file directly in the directory of the GrabBox app in Drobpox, it will be published.

Correspondence

――If you can move the image to the specified directory of Dropbox after taking the capture, it is good because it is the same as before. --Since you can change the save destination of screenshots on Mac, I prepared a script that does the following in Python.

  1. Save screenshots to a specific directory
  2. Monitor a specific directory to detect file creation (watchdog)
  3. If the created file is an image, rename it to a unique name.
  4. Retine seems to double the image size, so resize it to 1/2 (Pillow)
  5. Move the resized image to Dropbox's GrabBox directory
  6. Generate a dropbox publishing URL
  7. Copy the public URL to the clipboard (pbcopy)

The content of the script looks like this

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()

Finally, create a shell script that hits this script in the background

move2dropbox.command


nohup python /path/to/move2dropbox.py > /dev/null 2>&1 &

** Add the extension ".command" ** and register it in ** "System environment> Users and groups> Login items" **

79875dc4b71446639623ade7b08f0421.png

Now, when you log in, the above monitoring script will be executed without permission.

Summary

――Please tell us your recommended capture tool right now (urgent)

Postscript (2016/10/31)

List recommended ones

end

Recommended Posts

GrabBox didn't work on Sierra
Fcitx doesn't work on Flatpak
Install Scipy on Mac OS Sierra
LocateCenterOnScreen does not work on PyAutoGui
pygame doesn't work on macOS Mojave
Install Java2Python on macOS High Sierra (10.13)
I tried to install Docker on Windows 10 Home but it didn't work