How to open Tiddler from command line (I am running TiddlyWiki on Node.JS)

794 views
Skip to first unread message

Matt Groth

unread,
Feb 10, 2017, 11:23:59 PM2/10/17
to TiddlyWiki
Hi,

I'm a beginner at programming. I just set up m tiddlywiki with Node.JS. I'm having trouble figuring out how to use commands to control TiddlyWiki. Can someone point me to a "Hello World" step by step tutorial of how to make command for TiddlyWiki using Node.JS? Specifically I would like to commands to open and close tiddlers, but in general I am having a lot of trouble finding guides or APIs or anything. 

I also can't find any code to edit. Where is all the code that controls how Node.JS interacts with tiddlywiki? I've been searching my computer but can't find anything. My TiddlyWiki folder only has the .tid files and a .info file that doesn't seem too important.

PMario

unread,
Feb 11, 2017, 4:22:19 AM2/11/17
to TiddlyWiki
Hi Matt,

Can you describe a bit closer, what you try to achieve? ...

opening and closing tiddlers from the command line is not the purpose of the tw node version.

It's mainly used to "compile" file TiddlyWikis and to run the test server.
-m

Matt Groth

unread,
Feb 11, 2017, 11:50:08 PM2/11/17
to TiddlyWiki
Hi PMario,

I'm trying to automate TiddlyWiki from external scripts in whatever way possible. I have a system set up that is integrated with Spotify so my TiddlyWiki is its own little music organizer. 

Node.js helped me a lot because it gave me the option to create.tid files which can automatically be created and imported into my tiddlywiki.

I really like how it's going so far, but the only thing keeping it from being a seamless integration with Spotify is that I have to manually open the song tiddler every time a new song plays and close the last one.

Almost everything is set up. I have an AppleScript that triggers when a new Spotify song plays which can get the info required to find the tiddler associated with the song. All I need now is some way to command that tiddler to open and all others to close.

Thanks,
Matt

Jeremy Ruston

unread,
Feb 12, 2017, 9:00:50 AM2/12/17
to tiddl...@googlegroups.com
Hi Matt

I really like how it's going so far, but the only thing keeping it from being a seamless integration with Spotify is that I have to manually open the song tiddler every time a new song plays and close the last one.

Almost everything is set up. I have an AppleScript that triggers when a new Spotify song plays which can get the info required to find the tiddler associated with the song. All I need now is some way to command that tiddler to open and all others to close.

I think the way to do this is to use the TW5 HTTP API. You can POST updates to tiddler values; for example, updating $:/StoryList will update which tiddlers are shown in the story river. You can explore the API by running the client/server configuration of TiddlyWiki and monitoring network traffic in your browser developer tools as you perform operations on tiddlers.

Best wishes

Jeremy.


Thanks,
Matt


On Saturday, February 11, 2017 at 4:22:19 AM UTC-5, PMario wrote:
Hi Matt,

Can you describe a bit closer, what you try to achieve? ... 

opening and closing tiddlers from the command line is not the purpose of the tw node version.

It's mainly used to "compile" file TiddlyWikis and to run the test server.
-m

-- 
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/fc989cb4-4617-4173-b3e7-e8283481d0e6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Matt Groth

unread,
Feb 12, 2017, 4:33:53 PM2/12/17
to TiddlyWiki
Hi Jeremy,

Everything you talked about is new to me, but I really want to learn.

You can POST updates to tiddler values

Would this be a good tutorial to follow?

client/server configuration of TiddlyWiki

Are you referring to Node.js, or something else?

monitoring network traffic in your browser developer tools

I've never done this before. Would I use a program like this?

Thanks,
Matt

Matt Groth

unread,
Feb 13, 2017, 7:07:48 PM2/13/17
to TiddlyWiki
I spent a lot of time messing around and searching the internet to try to learn how to make an http request. This is the what I've managed to come up with:

console.log('pleasework starting');

var http = require('http');
http.post = require('http-post');

var newTidText = '{' +
    '"text": "Tiddler text",' +
    '"title": "WillThisWork",' +
    '"type": "text/vnd.tiddlywiki"' +
'}';

//var newTid = JSON.parse(newTidText);

res.setEncoding('utf8');
res.on('data', function(chunk) {
console.log(chunk);
});
});

I commented out JSON.parse because I think it might not be necessary, but I'm not sure. I found a program to watch network traffic, but I can't seem to do anything that this program will respond to.

So in terminal, I do:

node pleasework.js

And it gives the output:

pleasework starting

but still, I don't think anything is going through to my TiddlyWiki server. Meanwhile, whenever I do anything in my TiddlyWiki, the program picks it up and shows me all of the details. So I know exactly what I am looking for, but there must be something missing in my javascript code.

What am I missing?

Jeremy Ruston

unread,
Feb 14, 2017, 3:32:32 AM2/14/17
to tiddl...@googlegroups.com
Hi Matt

Firstly, apologies for the delayed reply.

I spent a lot of time messing around and searching the internet to try to learn how to make an http request.

That pretty much sums up what software developers do :)

This is the what I've managed to come up with:

That’s pretty close. Try this (untested):

console.log('pleasework starting');

var http = require('http');
http.post = require('http-post');

var newTid = {
text: "Tiddler text",
    title: "WillThisWork",
    type: "text/vnd.tiddlywiki"
};

res.setEncoding('utf8');
res.on('data', function(chunk) {
console.log(chunk);
});
});

The general idea is to compose the tiddler as a JavaScript object, and then use JSON.stringify() to convert it to a JSON string for sending over the network.

Best wishes

Jeremy


-- 
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.

Matt Groth

unread,
Feb 14, 2017, 8:32:50 AM2/14/17
to tiddl...@googlegroups.com

Hi Jeremy,

Thank you for explaining to me how data is sent over the network. Unfortunately, I'm still having a connection issue.

The code you posted continues to run without affecting my open TiddlyWiki, leaving a trace in my network manager, or producing an error.

On the other hand, I can connect using http.get:

var http = require('http');

  console.log("Got response: " + res.statusCode);
  console.log(res.headers);
}).on('error', function(e) {
console.log("Got error: " + e.message);
});

This produces the output:

Got response: 200

{ 'content-type': 'application/json',

  date: 'Tue, 14 Feb 2017 13:25:39 GMT',

  connection: 'close',

  'transfer-encoding': 'chunked' }


The http.get request can also be seen in my network manager. Do you know why the http.post might not be working, given that http.get does work?

I realized after your last post that you are the creator of TW. Thanks for all of the work you put in to making such a welcoming community! I'm very excited to learn more.

Best,
Matt

Jeremy Ruston

unread,
Feb 14, 2017, 9:43:08 AM2/14/17
to tiddl...@googlegroups.com
Hi Matt

On 14 Feb 2017, at 13:32, Matt Groth <mgro...@gmail.com> wrote:

The http.get request can also be seen in my network manager. Do you know why the http.post might not be working, given that http.get does work?

I’m not familiar with the http-post library that you’re using; perhaps it’s doing something funky. I’d be inclined to just use the http module unadorned.

Best wishes

Jeremy

Matt Groth

unread,
Feb 15, 2017, 7:11:00 PM2/15/17
to tiddl...@googlegroups.com
Hi Jeremy,

You're right, the regular http.request was the way to go. After I lot of fiddling, I managed to get update tiddlers with normal HTTP requests!

When I send a request, I see this terminal output:

syncer-server: Dispatching 'save' task: $:/StoryList
FileSystem: Saved file /
Users/Matt/TiddlyMusic/tiddlers/$__StoryList.tid


While the .tid file is updated instantly, my TiddlyWiki in Chrome does not sync with the server until I interact with it in some way, such as opening or closing a tiddler. Then, I see the above terminal output again and the changes from my HTTP request appear. 

However, changes to $:/StoryList do not sync at all, so I am still unable to automate the opening and closing of tiddlers. I have my $:/StoryList.tid text file open, and the 'list' property is changed in that file to exactly what I want. Also, the above terminal output occurs. However, when I do anything to my opened TiddlyWiki, whether it involves opening and closing tiddlers or not, the currently opened tiddlers in my browser simply overwrite whatever was in $_StoryList.tid previously.

How can I command TiddlyWiki in my browser to load changes to tiddler values, including $_StoryList.tid?

Thanks,
Matt

Matt Groth

unread,
Feb 19, 2017, 10:43:45 PM2/19/17
to tiddl...@googlegroups.com
Well I was going to post some of my updated findings and ask again for help, when all of a sudden I stumbled upon what may be the answer. All I had to do was run this javascript snippet in Chrome:

var storyList = "TiddlerIWantToOpen"
$tw.wiki.addTiddler({title: "$:/StoryList", text: "", list: storyList},$tw.wiki.getModificationFields());

This works perfectly. Now I am just looking for a way to automate the running of this snippet. (Does anyone happen to know how one can automate a javascript snippet in Chrome? In other words in what ways can I trigger the running of this snippet other than through Chrome developer tools?)

Is there a reason why all of the http stuff was suggested? This seems like a more direct solution.

Jeremy Ruston

unread,
Feb 20, 2017, 7:40:27 AM2/20/17
to tiddl...@googlegroups.com
Hi Matt

Well I was going to post some of my updated findings and ask again for help, when all of a sudden I stumbled upon what may be the answer. All I had to do was run this javascript snippet in Chrome:

var storyList = "TiddlerIWantToOpen"
$tw.wiki.addTiddler({title: "$:/StoryList", text: "", list: storyList},$tw.wiki.getModificationFields());


If you look at the “network” tab of developer tools while you run that snippet you’ll see that it generates the same underlying HTTP request as we’ve discussed earlier in the thread.

This works perfectly. Now I am just looking for a way to automate the running of this snippet. (Does anyone happen to know how one can automate a javascript snippet in Chrome?)

Chrome isn’t particularly easy to automate; you’d probably need to write an extension.

Is there a reason why all of the http stuff was suggested? This seems like a more direct solution.

Because your original post mentioned that you wanted to do display a tiddler “from an external script”. The most direct way for an external script to interact with TiddlyWiki under Node.js is the HTTP interface.

The issue you ran into whereby the change you made on the server wasn’t propagated to the browser is because the default polling interval is 60 seconds. You can manually force a poll by clicking the “refresh” button in the “Server” tab of control panel. 

Best wishes

Jeremy.

On Wednesday, February 15, 2017 at 7:11:00 PM UTC-5, Matt Groth wrote:
Hi Jeremy,

You're right, the regular http.request was the way to go. After I lot of fiddling, I managed to get update tiddlers with normal HTTP requests!

When I send a request, I see this terminal output:

syncer-server: Dispatching 'save' task: $:/StoryList
FileSystem: Saved file /
Users/Matt/TiddlyMusic/tiddlers/$__StoryList.tid


While the .tid file is updated instantly, my TiddlyWiki in Chrome does not sync with the server until I interact with it in some way, such as opening or closing a tiddler. Then, I see the above terminal output again and the changes from my HTTP request appear. 

However, changes to $:/StoryList do not sync at all, so I am still unable to automate the opening and closing of tiddlers. I have my $:/StoryList.tid text file open, and the 'list' property is changed in that file to exactly what I want. Also, the above terminal output occurs. However, when I do anything to my opened TiddlyWiki, whether it involves opening and closing tiddlers or not, the currently opened tiddlers in my browser simply overwrite whatever was in $_StoryList.tid previously.

How can I command TiddlyWiki in my browser to load changes to tiddler values, including $_StoryList.tid?

Thanks,
Matt

On Tuesday, February 14, 2017 at 9:43:08 AM UTC-5, Jeremy Ruston wrote:
Hi Matt

On 14 Feb 2017, at 13:32, Matt Groth <mgro...@gmail.com> wrote:

The http.get request can also be seen in my network manager. Do you know why the http.post might not be working, given that http.get does work?

I’m not familiar with the http-post library that you’re using; perhaps it’s doing something funky. I’d be inclined to just use the http module unadorned.

Best wishes

Jeremy

--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.

Matt Groth

unread,
Feb 20, 2017, 6:49:41 PM2/20/17
to TiddlyWiki
I finally got it to work just as I imagined! I can now create and open tiddlers in seconds containing whatever data I want. Thanks so much!

Jeremy,

If you look at the “network” tab of developer tools while you run that snippet you’ll see that it generates the same underlying HTTP request as we’ve discussed earlier in the thread.

I didn't know this, and it was extremely helpful.

Chrome isn’t particularly easy to automate; you’d probably need to write an extension.

You were right again, this is exactly what I needed to do.

The issue you ran into whereby the change you made on the server wasn’t propagated to the browser is because the default polling interval is 60 seconds. You can manually force a poll by clicking the “refresh” button in the “Server” tab of control panel. 

I am still unsure what you mean by this. When I tried modifying the $:/StoryList file, it did not change which tiddlers were open. Nothing I could do helped. Not refreshing, not restarting the server, and not clicking the "refresh" button in the "server" tab as you suggested. In fact, to quote the help tiddlers themselves: 

"The $:/StoryList tiddler is an example of a StateTiddler: a tiddler that is used to hold the state of the user interface. Changes to the user interface are made indirectly, by changing the underlying state tiddlers, and letting TiddlyWiki ripple the changes through the user interface." 

To be honest, I'm not sure I understand entirely. But what I do know is that $:/StoryList is fundamentally different from other tiddlers.

In the end, I accomplished my goal by injecting the javascript I mentioned above into the page through a Chrome extension. I have the injected script itself running on a separate server, so I can make changes to it and automate it.

Thanks again for your ideas, and for making such a versatile program.

Best,
Matt

imleg...@gmail.com

unread,
Nov 9, 2021, 9:08:05 AM11/9/21
to TiddlyWiki
Hi jeremy, could you help me on this post? 

I want to use python to do the same thing. But meet some problems. 
1. After http request the tiddler can't open immediately, need a manually reload
2. The tiddler opened before will close, after reload only leave the certain one I request. 

How too solve these two problem? Thank you. I can't get much help from the forum, thank you in advance. 

Reply all
Reply to author
Forward
0 new messages