Skip to content

Instantly share code, notes, and snippets.

@PostMonsterG
Created December 13, 2021 16:19
Show Gist options
  • Save PostMonsterG/c3cd6f2c4c5df9ca3bc56c0e21920871 to your computer and use it in GitHub Desktop.
Save PostMonsterG/c3cd6f2c4c5df9ca3bc56c0e21920871 to your computer and use it in GitHub Desktop.
A sample Drumkit script to open the contents of the current outline in iA Writer
<?xml version="1.0"?>
<opml version="2.0">
<head>
<title>OpenInIAWriterAsNewFile</title>
<dateCreated>Mon, 22 Nov 2021 02:05:51 GMT</dateCreated>
<flPublic>true</flPublic>
<urlPublic>http://drummer.scripting.com/PostMonsterG/OpenInIAWriterAsNewFile.opml</urlPublic>
<ownerTwitterScreenName>PostMonsterG</ownerTwitterScreenName>
<ownerName>Gary Teter</ownerName>
<ownerId>http://twitter.com/PostMonsterG</ownerId>
<urlUpdateSocket>ws://drummer.scripting.com:1232/</urlUpdateSocket>
<dateModified>Mon, 13 Dec 2021 16:12:35 GMT</dateModified>
<expansionState>1,7,14,21,22,24,25,32,33</expansionState>
<lastCursor>8</lastCursor>
</head>
<body>
<outline text="&lt;b&gt;Open in iA Writer as New File&lt;/b&gt;" created="Sun, 21 Nov 2021 20:08:38 GMT" isComment="false">
<outline text="This Drumkit sends the text from the current outline to iA Writer as a new document." created="Sun, 21 Nov 2021 01:37:48 GMT" isComment="true"/>
<outline text="" created="Tue, 23 Nov 2021 20:40:21 GMT" isComment="true"/>
<outline text="Created by Gary Teter. " created="Sun, 21 Nov 2021 01:45:54 GMT" isComment="true"/>
<outline text="This is the second version, updated with a note, in case anyone opens this file." created="Tue, 23 Nov 2021 20:27:32 GMT" isComment="true"/>
<outline text="" created="Thu, 25 Nov 2021 23:52:56 GMT" isComment="true"/>
<outline text="// &lt;b&gt;Please note, extremely important&lt;/b&gt;" created="Thu, 25 Nov 2021 23:52:59 GMT">
<outline text="I am leaving this file public, with this edit, because it is referenced in some issues on GitHub, and taking it down would be rude." created="Thu, 25 Nov 2021 23:57:10 GMT" isComment="true"/>
<outline text="I may update this file as I make new versions of this script, but please do not confuse this with anything resembling any sort of a software release process. You can't tell if I've changed it when you weren't looking. When I update this file with version three, version two will be gone. There will be no history. This is no way to release code, of course. I am just trying to state the obvious, so everybody knows it is obvious. I am pretty sure that particular formulation is from an editorial Ted Nelson wrote back when he was editor of Creative Computing." created="Fri, 26 Nov 2021 00:10:00 GMT" isComment="true"/>
<outline text="" created="Fri, 26 Nov 2021 00:01:51 GMT" isComment="true"/>
</outline>
<outline text="" created="Tue, 23 Nov 2021 20:27:11 GMT" isComment="true"/>
<outline text="// &lt;b&gt;To use this&lt;/b&gt;" created="Sun, 21 Nov 2021 01:46:44 GMT">
<outline text="Select &lt;b&gt;Open in iA Writer as New File&lt;/b&gt; from your scripts menu" created="Sun, 21 Nov 2021 01:46:51 GMT" isComment="true"/>
<outline text="The text from the current outline will be sent to iA Writer as a new document." created="Sun, 21 Nov 2021 20:05:11 GMT" isComment="true"/>
<outline text="Indentation and node structure is ignored." created="Sun, 21 Nov 2021 20:06:05 GMT" isComment="true"/>
<outline text="Each node becomes a new line of text." created="Mon, 22 Nov 2021 00:48:17 GMT" isComment="true"/>
<outline text="There is a 4,000-character limit to the amount of text which can be sent this way." created="Mon, 22 Nov 2021 00:25:43 GMT" isComment="true"/>
<outline text="" created="Tue, 23 Nov 2021 20:30:04 GMT" isComment="true"/>
</outline>
<outline text="// &lt;b&gt;To install this&lt;/b&gt;" created="Tue, 23 Nov 2021 16:23:24 GMT" isComment="false">
<outline text="Select this entire outline, i.e., the above &quot;&lt;b&gt;Open in iA Writer as New File&lt;/b&gt;&quot; node that contains all this" created="Mon, 22 Nov 2021 01:30:51 GMT" isComment="true"/>
<outline text="Copy it (cmd-C)" created="Mon, 22 Nov 2021 01:34:09 GMT" isComment="true"/>
<outline text="&lt;b&gt;File → Special Files... → Scripts menu... &lt;/b&gt;" created="Sun, 21 Nov 2021 01:54:15 GMT" isComment="true"/>
<outline text="Paste this outline (cmd-V) " created="Sun, 21 Nov 2021 01:55:14 GMT" isComment="true"/>
<outline text="There should be a new entry in your scripts menu named &quot;Open in iA Writer as New File&quot;" created="Mon, 22 Nov 2021 01:33:34 GMT" isComment="true"/>
<outline text="" created="Tue, 23 Nov 2021 16:29:35 GMT" isComment="true"/>
</outline>
<outline text="// &lt;b&gt;Here is the code&lt;/b&gt;" created="Tue, 23 Nov 2021 20:33:18 GMT">
<outline text="" created="Tue, 23 Nov 2021 20:33:29 GMT"/>
<outline text="EnsureBuffer()" created="Tue, 23 Nov 2021 20:35:47 GMT"/>
<outline text="GetOutlineContents()" created="Tue, 23 Nov 2021 20:36:51 GMT"/>
<outline text="const url = BuildURL()" created="Tue, 23 Nov 2021 20:37:08 GMT"/>
<outline text="webBrowser.openUrl( url )" created="Sun, 21 Nov 2021 23:27:59 GMT"/>
<outline text="" created="Tue, 23 Nov 2021 20:34:26 GMT"/>
<outline text="// &lt;b&gt;Functions&lt;/b&gt;" created="Tue, 23 Nov 2021 20:34:29 GMT">
<outline text="// &lt;b&gt;Ensure buffer&lt;/b&gt;" created="Mon, 22 Nov 2021 01:09:26 GMT">
<outline text="function EnsureBuffer() {" created="Tue, 23 Nov 2021 20:35:09 GMT">
<outline text="Probably not the right way to do this, but I ran into scoping issues with op.visitAll" created="Mon, 22 Nov 2021 01:25:30 GMT" isComment="true"/>
<outline text="if (root.temp == undefined) { root.temp = new Object() }" created="Sun, 21 Nov 2021 23:12:10 GMT" isComment="false"/>
<outline text="root.temp.chunks = &quot;&quot;" created="Sun, 21 Nov 2021 23:04:39 GMT"/>
<outline text="}" created="Mon, 22 Nov 2021 01:16:51 GMT"/>
<outline text="" created="Tue, 23 Nov 2021 20:35:28 GMT"/>
</outline>
</outline>
<outline text="// &lt;b&gt;Get the contents of the outline&lt;/b&gt;" created="Mon, 22 Nov 2021 01:09:31 GMT">
<outline text="function GetOutlineContents() {" created="Tue, 23 Nov 2021 20:36:06 GMT">
<outline text="const cursor = op.getCursor()" created="Wed, 07 Apr 2021 16:53:43 GMT"/>
<outline text="op.firstSummit()" created="Sun, 21 Nov 2021 22:02:10 GMT"/>
<outline text="op.visitAll( " created="Sun, 21 Nov 2021 20:12:27 GMT" isComment="false">
<outline text="function(node, level) {" created="Mon, 22 Nov 2021 01:05:01 GMT">
<outline text="const line = node.getLineText()" created="Sun, 21 Nov 2021 23:53:50 GMT"/>
<outline text="root.temp.chunks = root.temp.chunks + line + &quot;\n&quot;" created="Sun, 21 Nov 2021 23:46:13 GMT"/>
<outline text="})" created="Sun, 21 Nov 2021 20:14:25 GMT"/>
</outline>
</outline>
<outline text="op.setCursor( cursor )" created="Wed, 07 Apr 2021 16:54:22 GMT"/>
<outline text="}" created="Mon, 22 Nov 2021 01:16:55 GMT"/>
<outline text="" created="Tue, 23 Nov 2021 20:36:38 GMT"/>
</outline>
</outline>
<outline text="// &lt;b&gt;Construct the URL&lt;/b&gt;" created="Mon, 22 Nov 2021 01:11:48 GMT">
<outline text="function BuildURL() {" created="Tue, 23 Nov 2021 20:37:42 GMT">
<outline text="var encoded = encodeURI( root.temp.chunks )" created="Sun, 21 Nov 2021 23:49:22 GMT" isComment="false"/>
<outline text="encoded = string.multipleReplaceAll( encoded, {" created="Sun, 21 Nov 2021 23:38:15 GMT" isComment="false">
<outline text="&quot;#&quot; : &quot;%23&quot;" created="Sun, 21 Nov 2021 23:39:58 GMT"/>
<outline text="})" created="Sun, 21 Nov 2021 23:38:53 GMT"/>
</outline>
<outline text="const url = &quot;ia-writer://new?edit=true&amp;text=&quot; + encoded" created="Sun, 21 Nov 2021 23:20:29 GMT"/>
<outline text="return url" created="Tue, 23 Nov 2021 20:38:03 GMT"/>
<outline text="}" created="Mon, 22 Nov 2021 18:06:36 GMT"/>
</outline>
</outline>
</outline>
</outline>
</outline>
</body>
</opml>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment