Editorial Workflows

Editorial Backup

public workflow

Install Workflow...

This workflow contains at least one Python script. Only use it if you trust the person who shared this with you, and if you know exactly what it does.

I understand, install the workflow!

This is a workflow for Editorial, a Markdown and plain text editor for iOS. To download it, you need to view this page on a device that has the app installed.

Description: Fixed an issue with "ZIP does not support timestamps before 1980"
Enjoy!

Saves or restores a backup of all Editorial workflows, snippets, bookmarks, and local documents as a zip file in Dropbox (this requires the Dropbox account to be linked).

Please note: If you want to restore a backup on a different device, you first have to download the backup file (just tap on it in the document list). This is required because Editorial doesn't sync zip files by default.

Restoring a backup will *overwrite* all existing workflows, snippets, and bookmarks, so it's possible that you'll lose data this way. The best way to avoid any data loss is to create a backup before restoring anything.

Comments: Comment Feed (RSS)

There are no comments yet.

+ Add Comment

Workflow Preview
Show Alert ?
Title
Create or Restore?
Message
The backup of your workflows, snippets, bookmarks, and local documents will be created as a zip file in your Dropbox (EditorialBackup_Year: 2001_Month: 01_Day: 01-Hour: 01 (24h)_Minute: 01.zip). Editorial needs to be linked to Dropbox for this to work.
Button 1
Create Backup
Output Value
backup
Button 2
Restore...
Output Value
restore
Button 3
(don't show)
Output Value
Show Cancel Button
ON
Set Variable ?
Variable Name
Action
Value
Input
If "Backup" was selected... ?
Run the block if
Action
  • is Equal to
  • is Not Equal to
  • Contains
  • Doesn't Contain
  • Matches Regular Expression
backup
Create the Backup (Python) ?
Source Code
#coding: utf-8
import workflow
import editor
import os
from zipfile import ZipFile
import datetime
from io import BytesIO
import json
import shutil

t = datetime.datetime.today()
backup_filename = 'EditorialBackup_' + t.strftime('%Y_%m_%d-%H_%M') + '.zip'
wf_path = editor.get_workflows_path()
wf_files = os.listdir(wf_path)
snpt_path = os.path.expanduser('~/Library/Application Support/Snippets')
snpt_files = os.listdir(snpt_path)
doc_path = os.path.expanduser('~/Documents')
doc_files = os.listdir(doc_path)

zip_buffer = BytesIO()
with ZipFile(zip_buffer, 'w') as z:
	# Backup workflows:
	os.chdir(wf_path)
	for filename in wf_files:
		name, extension = os.path.splitext(filename)
		if extension in ('.wkflw', '.edcmd'):
			z.write(filename)
	# Backup snippets:
	os.chdir(snpt_path)
	for filename in snpt_files:
		name, extension = os.path.splitext(filename)
		if extension in ('.snpt', '.edcmd'):
			z.write(filename)
	# Backup bookmarks
	z.writestr('EditorBookmarks.json', json.dumps(editor.get_bookmarks('editor')))
	z.writestr('BrowserBookmarks.json', json.dumps(editor.get_bookmarks('browser')))
	# Backup local documents:
	os.chdir(doc_path)
	docZip = ZipFile('Documents.zip','a')
	for filename in doc_files:
		try:
			docZip.write(filename)
		except:
			pass
	docZip.close()
	z.write('Documents.zip')
	os.remove('Documents.zip')

zip_data = zip_buffer.getvalue()
editor.set_file_contents(backup_filename, zip_data, 'dropbox')
Show HUD ?
HUD Text
Backup Created
Duration
  • 1 Second
  • 2 Seconds
  • 3 Seconds
Icon
  • "Success"
  • "Error"
…End If
If "Restore" was selected.... ?
Run the block if
Action
  • is Equal to
  • is Not Equal to
  • Contains
  • Doesn't Contain
  • Matches Regular Expression
restore
List Backups (Python) ?
Source Code
#coding: utf-8
import workflow
import editor
import os
import re

wf_path = editor.get_workflows_path()
db_path = os.path.join(os.path.split(wf_path)[0], 'Dropbox')

backups = []
files = os.listdir(db_path)
for filename in files:
	if re.match('EditorialBackup_.*\\.zip$', filename):
		backups.append(filename)
workflow.set_output('\n'.join(backups))
Stop if no backups are found... ?
Run the block if
Input
  • is Equal to
  • is Not Equal to
  • Contains
  • Doesn't Contain
  • Matches Regular Expression
Show Alert ?
Title
No Backups Found
Message
No backup files were found. You might need to download them first, if you see grayed-out backup files in your Dropbox folder.
Button 1
OK
Output Value
Button 2
(don't show)
Output Value
Button 3
(don't show)
Output Value
Show Cancel Button
OFF
Stop ?
Stop
  • This Workflow
  • Repeat Block
Show HUD Alert
OFF
Message
Stopped
…End If
Select from List ?
Title
Select a Backup
List (Lines)
Input
Multiple Selection
OFF
Show in Popover
OFF
Show Warning Alert ?
Title
Warning
Message
This will replace all your workflows, snippets, bookmarks, and local documents with the ones that are stored in the selected backup (Input). Documents that are synced with Dropbox will not be changed.
Button 1
Continue
Output Value
Input
Button 2
(don't show)
Output Value
Button 3
(don't show)
Output Value
Show Cancel Button
ON
Restore the Backup (Python) ?
Source Code
#coding: utf-8
import workflow
import editor
from os import path
import os
from zipfile import ZipFile
import shutil
import json

backup_filename = workflow.get_input()
db_path = path.join(path.split(editor.get_workflows_path())[0], 'Dropbox')
backup_path = path.join(db_path, backup_filename)

with ZipFile(backup_path, 'r') as z:
	z.extractall(editor.get_workflows_path())
wf_path = editor.get_workflows_path()
snpt_path = os.path.expanduser('~/Library/Application Support/Snippets')
files = os.listdir(wf_path)
for filename in files:
	if filename == 'Snippets.edcmd' or path.splitext(filename)[1] == '.snpt':
		shutil.move(os.path.join(wf_path, filename), os.path.join(snpt_path, filename))
	if filename == 'EditorBookmarks.json':
		with open(os.path.join(wf_path, filename), 'r') as f:
			bookmarks = json.load(f)
			editor.set_bookmarks(bookmarks, 'editor')
		os.remove(os.path.join(wf_path, filename))
	if filename == 'BrowserBookmarks.json':
		with open(os.path.join(wf_path, filename), 'r') as f:
			bookmarks = json.load(f)
			editor.set_bookmarks(bookmarks, 'browser')
		os.remove(os.path.join(wf_path, filename))
	if filename == 'Documents.zip':
		doc_path = os.path.expanduser('~/Documents')
		with ZipFile(filename, 'r') as docszip:
			names = docszip.namelist()
			for name in names:
				try:
					docszip.extract(name, doc_path)
				except:
					pass
		os.remove(os.path.join(wf_path, filename))

editor.reload_workflows()
editor.reload_files()
Show HUD ?
HUD Text
Backup Restored
Duration
  • 1 Second
  • 2 Seconds
  • 3 Seconds
Icon
  • "Success"
  • "Error"
…End If