Editorial Workflows

Create File Shortcut

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: Creates a home screen shortcut to the file currently open in the editor, using a user-selected icon. Based on the excellent script by @olemoritz
Updated 3/1/14 - Improved method of file url retrieval.

Shared by: @that_pat

Comments: Comment Feed (RSS)

There are no comments yet.

+ Add Comment

Workflow Preview
Get Current File Name ?
Include Folder
OFF
Include Extension
OFF
Set Variable ?
Variable Name
label
Value
Input
Get Bookmark URL ?
Include Selected Range
OFF
Set Variable ?
Variable Name
shortcutURL
Value
Input
Run Python Script ?
Source Code
# This script adds a "Webclip" shortcut to your homescreen.
# You'll be asked for an icon (from your camera roll).
# Path to file, file name, and root (dropbox vs local) are
#	detected automatically.

import plistlib
import BaseHTTPServer
import webbrowser
import uuid
from io import BytesIO
import Image
import photos
import notification
import console
import workflow
import editor

class ConfigProfileHandler (BaseHTTPServer.BaseHTTPRequestHandler):
	config = None
	def do_GET(s):
		s.send_response(200)
		s.send_header('Content-Type', 'application/x-apple-aspen-config')
		s.end_headers()
		plist_string = plistlib.writePlistToString(ConfigProfileHandler.config)
		s.wfile.write(plist_string)
	def log_message(self, format, *args):
		pass

def run_server(config):
	ConfigProfileHandler.config = config
	server_address = ('', 0)
	httpd = BaseHTTPServer.HTTPServer(server_address, ConfigProfileHandler)
	sa = httpd.socket.getsockname()
	webbrowser.open('safari-http://localhost:' + str(sa[1]))
	httpd.handle_request()
	notification.schedule('Tap "Install" to add the shortcut to your homescreen.', 1.0)

def main():
	url = workflow.get_variable('shortcutURL')
	label = workflow.get_variable('label')
	icon = photos.pick_image()
	if not icon:
		return
	console.show_activity('Preparing Configuration profile...')
	data_buffer = BytesIO()
	icon.save(data_buffer, 'PNG')
	icon_data = data_buffer.getvalue()
	unique_id = uuid.uuid4().urn[9:].upper()
	config = {'PayloadContent': [{'FullScreen': True,
            'Icon': plistlib.Data(icon_data), 'IsRemovable': True,
            'Label': label, 'PayloadDescription': 'Configures Web Clip', 
            'PayloadDisplayName': label,
            'PayloadIdentifier': 'com.omz-software.shortcut.' + unique_id, 
            'PayloadOrganization': 'omz:software', 
            'PayloadType': 'com.apple.webClip.managed',
            'PayloadUUID': unique_id, 'PayloadVersion': 1,
            'Precomposed': True, 'URL': url}], 
            'PayloadDescription': label,
            'PayloadDisplayName': label + ' (Shortcut)', 
            'PayloadIdentifier': 'com.omz-software.shortcut.' + unique_id,
            'PayloadOrganization': 'omz:software', 
            'PayloadRemovalDisallowed': False, 'PayloadType': 
            'Configuration', 'PayloadUUID': unique_id, 'PayloadVersion': 1}
	console.hide_activity()
	run_server(config)

if __name__ ==  '__main__':
	main()