Showing posts with label JanusNode. Show all posts
Showing posts with label JanusNode. Show all posts

Saturday, March 9, 2013

Instant Crappy XML in TextWrangler with Applescript

One of the things I've been thinking about recently is JanusNode-style output in Quartz Composer, so that, I dunno, streams of nonsense can come out of goatse's ass or something. The JanusNode comes with a whole bunch of ready-made material in text files, so it'd save a whole lot of work if we could get those into QC.

QC will do a lot of stuff, but one of the things it won't do without massaging is get the contents of a text file. There are third-party plugins out there that'll do such things, but I like being able to export to a movie that'll play in Quicktime 7: from there those will render to honest-to-god video instead of remaining a collection of widgets executing graphical instructions in a proprietary environment.

XML files, as opposed to text files, are a different matter; .dae files are just big XML files and that annoying Mac screensaver that displays RSS feeds is parsing the same kind of thing. I know nearly nothing about XML, but it seems to me that the XML desired by QC is pretty damned dumb, and this works in an otherwise blank file:

<XML>
     <words>
          <data>goatse</data>
     </words>
     <words>
          <data>pygmy goat</data>
     </words>
</XML>


From there it's not a problem to get QC to choose between the two items, because it can count the amount of "words" tags and get what's in the "data" tags (or whatever other tag you wanna specify at that third level) according to some number-choosing operation: which would you like?

The problem here is that some of these lists are long. Like this one:



There are about 7000 lines in that file, many of them varieties of zombie.

Fortunately, though, that screenshot is of wonderful Mac freebie TextWrangler, and it can do shit, like crazy grep replacements across multiple files. First I thought I could be a smarty-pants and write one grep for a whole file, but I'm not that good, so I broke it up. If you do a find for "^.*$" and replace that result with "\t<words>\r\t\t\t<data>&</data>\r\t</words>" then every line in the file gets wrapped in the "words" and "data" tags and appropriately indented.



And, quite wonderfully, TextWrangler can save that search pattern in the little g-for-grep drop-down menu on the right and reapply it to anything you wanna deal with in future.

Then, since going to the start and end of a file and typing a few characters is backbreaking labour worthy only of the salt mines, you add saved find/replaces like so: find "\A^" and replace with "<XML>\r&", then find "\Z$" and replace with "&\r</XML>" and voila, list to XML file in three steps.

But wait! You say you are as unskilled as I am and EVEN LAZIER? Why then you use AppleScript, you lazy person, and you can use TextWrangler's capabilities to keep a script in the script menu, making it a one-step process. This last thing is a pain in the ass to get running in a satisfactory manner, thus this post for slugabeds everywhere. Who have Macs. And TextWrangler. And want to make word lists into XML files. Hello, possible person who may be me forgetting something! Remember to be less boring.

With a little bit of cribbing from this post and snippets of a script recorded within TextWrangler, I managed this very satisfying piece of work:

tell application "TextWrangler"
activate

replace "^.*$" using "\\t<words>\\r\\t\\t\\t<data>&</data>\\r\\t</words>" searching in document 1 options {search mode:grep, starting at top:true, wrap around:false, backwards:false, case sensitive:false, match words:false, extend selection:false, showing results:no} saving no

replace "\\A^" using "<XML>\\r&" searching in document 1 options {search mode:grep, starting at top:true, wrap around:false, backwards:false, case sensitive:false, match words:false, extend selection:false, showing results:no} saving no

replace "\\Z$" using "&\\r</XML>" searching in document 1 options {search mode:grep, starting at top:true, wrap around:false, backwards:false, case sensitive:false, match words:false, extend selection:false, showing results:no} saving no
end tell


And now that script (note the double-slashes in the AppleScript grep) lives in here in TextWrangler and works fine:





I might make it a drag-and-drop converter thing later if HEY IF I UPGRADE I GET PONIES.

Friday, September 14, 2012

Living in Hell



Over here is a list of aphorisms submitted by a whole bunch of people who have nothing better to do. It's in the nature of such a page that kooks "improve" upon whatever folk nonsense they've heard, mangling it and adding ALL CAPS AND EXCLAMATION POINTS!!! as they see fit, or simply coming up with their own hopeful motivational-poster wisdom. Then of course there are other people who begin never-ending projects using those brain-droppings and those people are Noble and their projects are Uniformly WONDERFUL!!!

He who is not a sugar substitute to himself doesn't know himself.
He who is not a freak to himself doesn't know himself.
Nobody can make you feel abnormal without your queen.
The bean is out there.
No president can make you feel x-rated without your shot.
Nobody can make you feel egocentric without your thing.
It's not what we prick that shows us up, it's what we don't prick.
It's not what we offend that shows us up, it's what we don't offend.
It's not what we rub that shows us up, it's what we don't rub.
The great-aunt is out there.
It's not what we terminate that shows us up, it's what we don't terminate.
The spider is out there.
Harry Truman can make you feel wasteful without your metaphor.
Congresses are signs of God's work.
Nobody can make you feel ugly without your mink.
Nobody can make you feel ecstatic without your moron.
Ray Charles can make you feel bashful without your specialist.
It's not what we whip that shows us up, it's what we don't whip.
Nobody can make you feel guilty without your terrorist.
The rabbi is out there.

Current JanusNode is 3.14.

Saturday, April 21, 2012

Reprisals

One of the things I'd never figured out about JanusNode was how "RepriseTextDNA" worked. I think I've got it and it's simultaneously more and less powerful than I thought, in the JanusNode way. Due to combinations of unexpected behaviours, slight but meaningful changes to the code on the author's part and bad coding by yours truly, I think I finally get it.



So, here's my little set of testing files. If you have a named folder inside the TextDNA folder and you start up your JanusNode that folder will appear in the main drop down folder, and when you click Janus to write text it'll process the text file named after the folder first. The only line in that file is this one (and note that every line that starts with "Subject" is a single line.):

Subject(Tester) < loadTextDNAfile("0Tester") > < chooseTextDNA(title1) >

This loads the second file in the folder, 0Tester, and chooses a line (title1) to start with. Multiple files are a necessity if you have a starting place in mind: JanusNode is built to be capricious and will choose any goddamned line it pleases unless you force it to do things differently. One line, one instruction will make it do one thing. On to 0Tester, then, and this batch of nonsense:

Subject(title1) < assign(Chooser,"100,200") > < chooseTextDNA(test1) >
Subject(test1) < RepriseTextDNA(Chooser) > < chooseTextDNA(test2) >
Subject(test2) < RepriseTextDNA(Chooser) > < chooseTextDNA(DKW1) >
Subject(DKW1) "Your mother is still a whore." < chooseTextDNA(test1) >
Subject(100) "fuck"
Subject(100) "that"
Subject(100) "shit" < chooseTextDNA(test2) >
Subject(100) "asshole" < chooseTextDNA(test2) >
Subject(200) "fluffy" < chooseTextDNA(test2) >
Subject(200) "bunnies" < chooseTextDNA(test2) >
Subject(200) "love" < chooseTextDNA(test2) >
Subject(200) "smiles" < chooseTextDNA(test2) >


We'll get to the inherent wrongness some may spot in a sec. "Subject(title1)" loads up a variable called "Chooser" with either "100" or "200" and then moves on to "Subject(test1)". There's where we took a stab at < RepriseTextDNA(Chooser) >. Initially, because it was called "reprise" I thought it was going to be a way to store a line of already-used TextDNA and the documentation is somewhat baffling, referring to incomplete examples that don't exist. C'est la vie. So I banged away at it, wondering why I wasn't getting repetition out of the thing, examined the Robot Johnson files, and discovered that it wasn't doing that either; repeated lines (with variations) were coded in. SO, back to the manual to Actually Read The Sentences Properly and we find out that < RepriseTextDNA(Chooser) > is not really different from < chooseTextDNA(title1) >, it's just that the subject line chosen can be assigned from a variable, and "reprise" is an eccentric name for the function. Hooray! That can still lead to some ferociously complicated stuff, but let's check the output of this one:
shit fuck Your mother is still a whore. Asshole shit fuck Your mother is still a whore. That that Your mother is still a whore. That shit shit asshole asshole that Your mother is still a whore. That shit fuck Your mother is still a whore. That that Your mother is still a whore. Shit fuck Your mother is still a whore.
OR
bunnies smiles smiles smiles bunnies love smiles fluffy smiles fluffy fluffy bunnies love smiles smiles smiles bunnies fluffy love love fluffy fluffy love
So, when "assign" grabs "100" you get JanusPottyMouth, when it grabs "200" you get JanusFluffyBunny. Which is cheatable in other ways, but they're longer (multiplying instances of lines and files). So now I have these ideas around villanelles.

Note that due to various problems getting my shit together I was getting no output and tried everything and ended up DOING IT RONG: the "< chooseTextDNA(test2) >" in most of the 100 and 200 subject lines is there because of that, and therefore the 200 subject lines keep doubling back before the execution of DKW1, thus keeping fluffy bunnies loving and smiling. Or so you would think.
smiles bunnies bunnies love love love bunnies Your mother is still a whore. Smiles bunnies smiles fluffy love love fluffy smiles love love bunnies love fluffy bunnies fluffy fluffy
It just does its own thing sometimes.