Editorial workflow to create a file in a Dropbox subfolder.

Editorial workflow to create a file in a Dropbox subfolder.

Update: After posting this I found a much nicer workflow to authenticate with dropbox. Using it as the first step in this workflow would probably be much better.

Sometimes working on your writing workflow is more fun than actually writing. But, it usually provides for some interesting subjects too.

I was having fun automating my blog build process using Siri after I stumbled across this fun method. It works really well for quick posts from my phone but I also use Editorial as my main iPad writing app so I also wanted a workflow there that could also trigger the refresh. Here’s what I came up with:

#coding: utf-8
import dropbox
import os
import StringIO

app_token_file = 'dropbox_token.txt'
app_key = 'YOUR-KEY'
app_secret = 'YOUR-SECRET'
access_type = "dropbox"

session = dropbox.session.DropboxSession(app_key,app_secret,access_type)

try:
	token_file = open(app_token_file)
	token_key,token_secret = token_file.read().split('|')
	token_file.close()
except IOError:
	token_key = None 

if token_key:
	session.set_token(token_key,token_secret)
else:
	request_token = session.obtain_request_token()
	url = session.build_authorize_url(request_token)
	print "url:", url
	print "Please authorize in the browser. After you're done, press enter."
	raw_input()

	# This will fail if the user didn't visit the above URL and hit 'Allow'
	access_token = session.obtain_access_token(request_token)

	token_file = open(app_token_file,'w')
	token_file.write("%s|%s" % (access_token.key,access_token.secret) )
	token_file.close()

client = dropbox.client.DropboxClient(session)

output = StringIO.StringIO()
output.write('generated via editorial workflow.\n')

res = client.put_file('/Apps/IFTTT/iOS Reminders/Task/refresh_blog.txt', output)

I created this in a Python workflow. It connects to Dropbox via the API and then creates a file in the appropriate place (matching the IFTTT location in the Siri method above)1. To use the workflow yourself, you need to:

  1. Register a new app on the Dropbox App Console for your workflow2.
  2. Copy your keys From the app console into the top of the workflow script.
  3. And authorize the workflow. The first time you run the workflow, you need to look in the Editorial console pane and copying the authorization URL into the browser pane. Once you log into Dropbox and authorize your app, return to the Console pane and tap the bottom bar then hit return. The token will be stored so the next time the workflow runs so it won’t require authorization again.

There’s probably lots of other neat things you could do by creating file in Dropbox from text selections so feel free to customize this however you like.

  1. I tried to use Editorial’s built in Dropbox options but there didn’t seem to be a way to specify a subfolder.

  2. Since you will be the only one using the app you can just use a “development” version, you won’t need production access.