Editorial Workflows

Workspaces...

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: This workspace switcher allows you to have multiple sets of bookmarks and workflows, e.g. for different types of documents.

Shared by: @olemoritz

Comments: Comment Feed (RSS)

There are no comments yet.

+ Add Comment

Workflow Preview
Set Variable ?
Variable Name
List Title
Value
Workspaces
List Workspaces... (Python) ?
Source Code
import workflow
import os
from glob import glob

def get_active_workspace_name():
	try:
		with open('active_workspace', 'r') as f:
			active_workspace = f.read()
			return active_workspace
	except IOError:
		return None

workspace_names = [os.path.splitext(x)[0] for x in glob('*.workspace')]
active_workspace = get_active_workspace_name()
if active_workspace is not None:
	workflow.set_variable('List Title', 'Workspaces (Active: ' + active_workspace + ')')
output_list = ['Save Workspace as...']
if len(workspace_names) > 1:
	output_list.append('Delete Workspace(s)...')
output_list += workspace_names
workflow.set_output('\n'.join(output_list))
Select from List ?
Title
%var:List Title
List (Lines)
Input
Multiple Selection
OFF
Show in Popover
ON
Set Variable ?
Variable Name
Workspace
Value
Input
Save Workspace as... ?
Run the block if
Workspace
  • is Equal to
  • is Not Equal to
  • Contains
  • Doesn't Contain
  • Matches Regular Expression
Save Workspace as...
Request Text Input ?
Title
Workspace Name
Initial Text
  • Single Line
  • Multiple Lines
Keyboard Options:
Set Variable ?
Variable Name
New Workspace
Value
Input
Run Python Script ?
Source Code
import workflow
import editor
import os
from zipfile import ZipFile
import pickle
from io import BytesIO

def get_current_workspace_dict():
	wf_path = editor.get_workflows_path()
	files = os.listdir(wf_path)
	buffer = BytesIO()
	with ZipFile(buffer, 'w') as z:
		for filename in files:
			extension = os.path.splitext(filename)[1]
			if extension == '.edcmd' or extension == '.wkflw':
				z.write(filename)
	workflow_data = buffer.getvalue()
	editor_bookmarks = editor.get_bookmarks('editor')
	browser_bookmarks = editor.get_bookmarks('browser')
	workspace = {'workflow_data': workflow_data,
	             'editor_bookmarks': editor_bookmarks,
	             'browser_bookmarks': browser_bookmarks}
	return workspace

def get_active_workspace_name():
	try:
		with open('active_workspace', 'r') as f:
			active_workspace = f.read()
			return active_workspace
	except IOError:
		return None

def set_active_workspace_name(name):
	with open('active_workspace', 'w') as f:
		f.write(name)

selected_workspace_name = workflow.get_input()
workspace = get_current_workspace_dict()

#Save new workspace, and set it as active:
with open(selected_workspace_name + '.workspace', 'w') as f:
	pickle.dump(workspace, f)
	set_active_workspace_name(selected_workspace_name)
Show HUD ?
HUD Text
Workspace Created: New Workspace
Duration
  • 1 Second
  • 2 Seconds
  • 3 Seconds
Icon
  • "Success"
  • "Error"
Stop ?
Stop
  • This Workflow
  • Repeat Block
Show HUD Alert
OFF
Message
Stopped
…End If
Delete Workspace(s)... ?
Run the block if
Workspace
  • is Equal to
  • is Not Equal to
  • Contains
  • Doesn't Contain
  • Matches Regular Expression
Delete Workspace(s)...
List Workspaces... (Python) ?
Source Code
import workflow
from glob import glob
import os

def get_active_workspace_name():
	try:
		with open('active_workspace', 'r') as f:
			active_workspace = f.read()
			return active_workspace
	except IOError:
		return None

workspace_names = [os.path.splitext(x)[0] for x in glob('*.workspace')]
active_workspace = get_active_workspace_name()
if active_workspace in workspace_names:
	workspace_names.remove(active_workspace)
workflow.set_output('\n'.join(workspace_names))
Select from List ?
Title
Delete Workspace(s)...
List (Lines)
Input
Multiple Selection
ON
Show in Popover
OFF
Show Alert ?
Title
Delete?
Message
Do you really want to delete the following workspace(s)? Input
Button 1
Delete
Output Value
Input
Button 2
(don't show)
Output Value
Button 3
(don't show)
Output Value
Show Cancel Button
ON
Delete selected... (Python) ?
Source Code
#coding: utf-8
import workflow
import os
import console

action_in = workflow.get_input()
deleted_workspaces = action_in.splitlines()

for name in deleted_workspaces:
	os.remove(name + '.workspace')

num_deleted = len(deleted_workspaces)
if len(deleted_workspaces) > 1:
	console.hud_alert(str(num_deleted) + ' Workspaces Deleted')
elif num_deleted == 1:
	console.hud_alert('Workspace Deleted')
Stop ?
Stop
  • This Workflow
  • Repeat Block
Show HUD Alert
OFF
Message
Stopped
…End If
Switch to Workspace... (Python) ?
Source Code
import workflow
import editor
import os
from zipfile import ZipFile
import pickle
from io import BytesIO

def get_current_workspace_dict():
	wf_path = editor.get_workflows_path()
	files = os.listdir(wf_path)
	buffer = BytesIO()
	with ZipFile(buffer, 'w') as z:
		for filename in files:
			extension = os.path.splitext(filename)[1]
			if extension == '.edcmd' or extension == '.wkflw':
				z.write(filename)
	workflow_data = buffer.getvalue()
	editor_bookmarks = editor.get_bookmarks('editor')
	browser_bookmarks = editor.get_bookmarks('browser')
	workspace = {'workflow_data': workflow_data,
	             'editor_bookmarks': editor_bookmarks,
	             'browser_bookmarks': browser_bookmarks}
	return workspace

def get_active_workspace_name():
	try:
		with open('active_workspace', 'r') as f:
			active_workspace = f.read()
			return active_workspace
	except IOError:
		return None

def set_active_workspace_name(name):
	with open('active_workspace', 'w') as f:
		f.write(name)

def switch_workspace(workspace):
	editor_bookmarks = workspace['editor_bookmarks']
	browser_bookmarks = workspace['browser_bookmarks']
	workflow_data = workspace['workflow_data']
	workflow_zip = BytesIO(workflow_data)
	with ZipFile(workflow_zip, 'r') as z:
		z.extractall(editor.get_workflows_path())
	editor.reload_workflows()
	editor.set_bookmarks(editor_bookmarks, 'editor')
	editor.set_bookmarks(browser_bookmarks, 'browser')

selected_workspace = workflow.get_variable('Workspace')
active_workspace = get_active_workspace_name()
if active_workspace == selected_workspace or selected_workspace == '':
	workflow.stop()
elif active_workspace is not None:
	#Save current workspace:
	workspace = get_current_workspace_dict()
	with open(active_workspace + '.workspace', 'w') as f:
		pickle.dump(workspace, f)
#Switch to selected workspace, and set it as active:
with open(selected_workspace + '.workspace', 'r') as f:
	workspace = pickle.load(f)
	switch_workspace(workspace)
	set_active_workspace_name(selected_workspace)
Show HUD ?
HUD Text
Workspace
Duration
  • 1 Second
  • 2 Seconds
  • 3 Seconds
Icon
  • "Success"
  • "Error"