Juha-Matti Santala
Community Builder. Dreamer. Adventurer.

I wrote my first Dropzone 4 action

Let me tell you a quick story of a great developer experience.

I learned about, installed and got excited about two separate apps for macos today: Iina and Dropzone.

Iina is a very slick video player that looks a lot like Quicktime Player (which I've used for 90% of my local video viewing) but it has a few nice extra features like natively playing video streams from services like Youtube and others and more customization options than QT Player.

Dropzone is a menu bar tool that enables you to do quite a lot: you can temporarily store stuff (images, files, URLs, text, etc) in it or you can use it to activate different actions like moving files to folders, uploading them to internet services and more. It also allows you to build your own actions and that's where this story begins.

Add to Grid -> Develop Action

I'll have to say: I've never had a faster and better developer experience for building a custom plugin/workflow/extension ever than I had with Dropzone 4.

What I wanted to do, was to have a way to drag-and-drop a Youtube URL into Dropzone and have it open Iina with that stream. Instead of having to dive deep into developer documentation, there's a button that says "Add to Grid" which opens a menu and in addition to some pre-existing items, there's "Develop Action..." which, after a few settings clicked in the UI, opened up XCode with a template code in Python (you can also choose Ruby if you'd like).

Open a Youtube stream in Iina

import subprocess

def dragged():
    url = items[0]
    if 'youtube.com' not in url:
        dz.fail('Not valid Youtube URL')
        subprocess.call(['/usr/bin/open', f'iina://weblink?url={url}'])

The template code that Dropzone offered was good enough to give me a sense of how to write an Action in Python. I deleted it and wrote my own dragged function implementation (which is what gets run when something is dragged on top of the icon in Dropzone).

It gives a global (yikes!) items variable that contains a list of the items the user dragged in. In my case, a singular Youtube URL. I did some very crude and simplistic validation to see that I'm not sending non-Youtube links to Iina – although this doesn't actually prevent the user from dragging a non-video link like youtube.com. I can always fix the validation to be something smarter later.

If the URL fits, we run a subprocess to open a iina://weblink with our URL and voilà, it opens up Iina with the desired video.

Syntax Error

Sign up for Syntax Error, a monthly newsletter that helps developers turn a stressful debugging situation into a joyful exploration.