How to automatically upload videos encoded with Apple Compressor

“Run Shell Script” Action

curl -F access_token=YOUR_ACCESS_TOKEN_HERE -F file=@”$1" https://upload.wistia.com/

“Run JavaScript” Action

function run(input) {

var response = JSON.parse(input);

if (response.name) {
var dateAndTime = new Date(response.created);
var status = `Your file "${response.name}" was uploaded successfully on ${dateAndTime}`;
} else if (response.code) {
var status = `Your file upload failed with the following error: "${response.code}: ${response.detail}"`;
} else if (response.error) {
var status = `Your file upload failed with the following error: "${response.error}"`;
} else {
var status = 'Your Wistia upload has failed.';
}

return status;
}

Full Walkthrough

Create an Automator Workflow

Automator is a built-in application that allows you to create “workflows” to help with repetitive tasks on your Mac. Essentially, it takes an input, runs an Action based on that input, and returns a result. You can chain these Actions together to create powerful workflows.

“Run Shell Script” Action

The first Action we need to create is called “Run Shell Script.” Make sure to select Shell: bin/bash and Pass input: as arguments

curl -F access_token=YOUR_ACCESS_TOKEN_HERE -F file=@”$1" https://upload.wistia.com/
@"$1"

Optional Next Steps

Technically the “Run Shell Script” Action is all you will need to upload to Wistia after Compressor finishes encoding, however I recommend creating a way to update yourself on the status of the upload. If you have your email setup using Apple Mail, you can easily send yourself a message with the final upload status.

result=$(curl -i -F access_token=YOUR_ACCESS_TOKEN_HERE -F file=@"$1" https://upload.wistia.com/)echo "${result}" \n >> Wistia_Upload.log

Parse JSON Response with “Run JavaScript” Action

The first step in creating the email workflow will be to parse the response that the Wistia API has sent back to us. Luckily Wistia sends back JSON in the response body, and provides documentation on the data structure we can expect for a successful upload, as well as possible errors.

function run(input) {

var response = JSON.parse(input);

if (response.name) {
var dateAndTime = new Date(response.created);
var status = `Your file "${response.name}" was uploaded successfully on ${dateAndTime}`;
} else if (response.code) {
var status = `Your file upload failed with the following error: "${response.code}: ${response.detail}"`;
} else if (response.error) {
var status = `Your file upload failed with the following error: "${response.error}"`;
} else {
var status = 'Your Wistia upload has failed.';
}

return status;
}

Use “New Mail Message” and “Send Outgoing Messages” Actions to create and send an email.

The final step in the Automator workflow is to take the value of status returned from the previous Action, and pass it to the body of an email using the “New Mail Message” Action. Make sure to fill in the email address and subject fields to ensure that the status message gets passed to the email body.

Using the Automator Workflow in Compressor

Once you’ve saved the Automator Workflow, you can finally add it to your Compressor project. To do this, just click on the clip you’re exporting, and in the Job tab scroll all the way down to the “Action” section. Set the “When done:” button to Run Automator Workflow, and choose your Workflow file.

Wait, did I only make this tutorial to prove that I was good at skateboarding in 2016?

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Arthur Wilton

Arthur Wilton

41 Followers

Software Developer and Video/Post Production Professional. Recent graduate of Flatiron School.