-
-
Save judithdrive/cb416e33c170967dfe1e to your computer and use it in GitHub Desktop.
Clipslate.py adapted for Editorial.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| javascript: | |
| (function (t,r) { | |
| window.location = 'pythonista://clipto?action=run&argv=' + encodeURIComponent(document.title) + '&argv=' + encodeURIComponent(location.href) + '&argv=' + t + '&argv=' + r + '&argv=' + encodeURIComponent(document.getSelection()||''); | |
| })('Sublime','Dropbox') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- coding: utf-8 -*- | |
| """ | |
| Adapted from clipslate.py for clipping into Editorial: | |
| - Send the highlighted text as an argument rather than via the clipboard. This requires the use of 'document.getSelection()', which only works when the bookmarklet is activated from the Safari bookmark bar. When activated from the bookmark button, selections are lost. This modification is just a personal preference since the clipboard is wiped out between Pythonista and Editorial anyway. | |
| - Two parameters in the bookmarklet determine the destination file and its root. The following bookmarklet writes to 'Clips/Sublime.md', in the DropBox root: | |
| javascript: (function () { | |
| target = 'Sublime'; | |
| root = 'Dropbox'; | |
| window.location = 'pythonista://clipto?action=run&argv=' + encodeURIComponent(document.title) + '&argv=' + encodeURIComponent(location.href) + '&argv=' + target + '&argv=' + root+ '&argv=' + encodeURIComponent(document.getSelection()||''); | |
| })() | |
| or, suitably compacted as a bookmarklet: | |
| javascript:(function%20()%7Btarget='Sublime';root='Dropbox';window.location='pythonista://clipto?action=run&argv='+encodeURIComponent(document.title)+'&argv='+encodeURIComponent(location.href)+'&argv='+target+'&argv='+root+'&argv='+encodeURIComponent(document.getSelection()%7C%7C'');%7D)() | |
| - This requires an Editorial action called 'Append' that moves the cursor to the end of the file, then writes the clipboard. | |
| - The 'encodeURIComponent()' may help with unicode characters in the highlighted text, though not verified. | |
| - If the target Editorial file doesn't exist, the action fails, but in the Editorial app with the clipboard payload intact. It can be recovered by creating the specified target file, and then applying the 'Append' action. Perhaps an Editorial create-if-necessary-and-append action is the solution. | |
| - It seems that Editorial's Python could perform Pythonista's formatting to make a one step action. | |
| --- | |
| clipslate.py: capture page title and url and current | |
| iOS system clipboard and append to a notesy.app file | |
| in markdown format in order to collect a series of dated, | |
| named and linked pieces of copied plain text for | |
| later processing | |
| notsey.app x-callback-url implementation is documented at http://notesy-app.com/weblog/files/b7e15801e5b4448495eaaccfdb374cc7-20.htm | |
| This script can be adapted for any other x-callback-url app with an append action | |
| 2013-04-27 | |
| (c) 2013 Richard Careaga, all rights reserved. | |
| Subject to license terms and conditions at | |
| http://richard-careaga.com/lic2013.txt | |
| adapted from clip2poster | |
| (http://omz-software.com/pythonista/forums/discussion/190/posting-to-wordpress-from-safari-with-clipboard) | |
| install this script to your pythonista.app top-level directory | |
| Create the following bookmark in your browser app with the name | |
| 'cs' (or your choice): | |
| javascript:window.location='pythonista://clipslate?action=run&argv='+encodeURIComponent(document.title)+'&argv='+encodeURIComponent(location.href); | |
| Then navigate to target page, highlight some text, copy it and tap the cs bookmark | |
| Known bug: does not handle unicode characters | |
| Known limitation: system clipboard copies plain text from browsers, not HTML, so copied embedded limks are lost | |
| """ | |
| # def clipper(): | |
| import sys | |
| import clipboard | |
| import urllib | |
| import webbrowser | |
| from datetime import datetime | |
| # convenience definitions | |
| today = datetime.today() | |
| the_date = today.strftime('%Y-%m-%d') | |
| # sys.argv[0] = this appname | |
| # sys.argv[1] = the webpage title | |
| # sys.argv[2] = the webpage url | |
| # sys.argv[3] = the target document (without the prefix "Clip" or the extension ".md") | |
| # sys.argv[4] = the document root, "local" or "dropbox" | |
| # sys.argv[5] = the selected text | |
| the_title = sys.argv[1] | |
| the_url = sys.argv[2] | |
| the_doc = sys.argv[3] | |
| the_root = sys.argv[4] | |
| the_clip = sys.argv[5].strip() | |
| # layout and format in markdown | |
| first_line = '* Clipped from [' + the_title + '][] on ' + the_date | |
| the_link = '[' + the_title + ']: ' + the_url | |
| payload = first_line + '\n\n>' + the_clip + '\n\n' + the_link + '\n\n---\n\n' | |
| # copy the completed formatted clipping onto the system clipboard | |
| clipboard.set(payload) | |
| # construct the Editorial url | |
| target = 'editorial://open/Clips/' + the_doc + '.md?root=' + the_root + '&command=Append' | |
| # append the reloaded clipboard to the specified Editorial file | |
| webbrowser.open(target) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment