"Literary Toolbox" Palette

Thanks for the update.
To ensure that all new readers see your latest update, I added your update post to your OP. Please feel free to further edit if you so desire.

Literary Toolbox 10c

This release shows Grammarian citations in context (at last). It also revises the HTML window CSS slightly.

ss-501
You won't have to reinstall any of the Perl modules. Only the Keyboard Maestro palette changes.

Updated documentation is included in the ZIP file.

Literary Toolbox.10c.zip (811.9 KB)

Here's a slight change to the Custom HTML of the Most Used Words and Word Frequency macros I'm trying out locally that you may want to use:

	<style type="text/css">
body{background-color:black;font:.80em "Lucida Grande",serif;color:#36aac2;margin:0;}#title{background-color:#36aac2;color:white;text-shadow:2px 2px 3px #26aac2;padding-left:12px;font-size:1.1em;width:228px;padding-top:5px;padding-bottom:5px;margin-bottom:8px;text-transform:uppercase;letter-spacing:6px;font-weight:bold}#text{align:left;padding:2em;padding-top:.25em;column-count:2}
	</style> 

That column-count:2 at then end gives you a two-column display for those lists. The CSS also deletes the span section, which isn't used.

1 Like

I added an update notice to your OP at the top.

Thanks, tried to edit it but wasn't allowed.

I think the command for custom palette change through the terminal is wrong in the manual. It is missing "-string". So it worked for me after entering the command like this:

defaults write com.stairways.keyboardmaestro.engine CustomPaletteTheme -string "0,0,0, 190,72,76, 0,0,100"

Thanks @slimhan. That appears to be a change in syntax.

In Custom Palette Style Colors?, Peter Lewis cites the stringless syntax (but that was 2016). And I see that in the Wiki Preferences reference it is now stringed.

On another note, when I moved to Mojave I had to change the way Spell Catcher is called to check a document. I still prefer its batch mode but I suspect I'm the last person on earth using it.

I'll include that revision (as well as the two-column Most Used Words and Word Frequency reports) in the update coming shortly.

Again, thanks for pointing that out.

1 Like

Literary Toolbox 10e

This release uses a two-column display for the Most Used Words and Word Frequency reports, updates the Spell Catcher batch spell check to work with Mojave (thanks to Chris Stone) and updates the documentation to use the current syntax for the custom theme (thanks to slimhan).

LiteraryToolbox.10e.zip (812.8 KB)

2 Likes

LITERARY TOOLBOX II

Just a note to say I'm providing a version of this macro that works on very large files.

I tried running a few of the analyses on an 84K file with the original macro group and it overran the environment size. So rather than reading the selection stored in a Keyboard Maestro variable, this version writes it to a temporary file, reads it into a Perl variable and deletes the temporary file, avoiding filling the environment space.

Keyboard Maestro can accept a variable of any size, as I understand it, but once the system environment is full, it deletes the largest variable, which causes the original version of this macro group to fail. This version avoids that.

Seems to work fine in my limited testing on two machines. It seems as fast as the original on an SSD but it's no slouch on a hard disk.

Update: Here it is. The temporary file is written to Users/Shared/temp.txt because that location doesn't depend on your user name. It's also deleted right after it is read. This version uses Option-F10 as the trigger (the original used F10) so you can use both.

BTW, no need to reinstall any of the supporting software. Just import the updated macro Literary Toolbox II.

Update (21 Jan. 2021): This version fixes an issue with the Concordance that did not maintain the original line endings in the report.

Update (9 Feb. 2021): Revised the location and name of the temporary file from Users/Shared/temp.txt to tmp/LT-temp.txt. It is, however, deleted immediately after it is read. Note, too, that some functions (like the grammar check) take a while to run on longer texts. This version, however, does not show a progress bar for them.

Update (8 March 2021): Updated code to handle revised Emotion module. Removed restrictions on InDesign CS5 as obsolete. Added WordNet Lookup option for selected word [undocumented beta]. And I just tweaked the WordNet Lookup with 1) a link on the headline word to the Princeton form for deeper exploration and 2) colored examples.

Update (10 March 2021): I've added the PDF of a draft of the revised manual as a separate download below.

Update (11 March 2021): A few changes:
• Added local WordNet Lookup option
• Change hot key for WordNet options
• Activated WordNet links in remote option
• Updated Spell Catcher word lookup
• Revised Spell Check Document to include some non-standard keyboard shortcuts which you can extend easily for other applications
• Revised documentation

Literary Toolbox II Macros.kmmacros (203.1 KB)

LiteraryToolbox.pdf.zip (740.2 KB)

Hey Mike,

I'd stay out of the user space and use the /tmp directory.

-Chris

I suppose I could prompt for a location if the corresponding variable were blank rather than use a hard-coded location available on any machine. But what's the advantage? Or, to put it another way, what's the disadvantage to using the Users/Shared location briefly?

NB: I just saw a typo in the original message regarding the location of the temporary file. It's in Users/Shared not Users alone.

Hey Mike,

The /tmp directory is available on all Unix machines and is specifically designed as a destination for temporary files.

Staying out of the user space when you don't need to be in there is a basic safety measure.

-Chris

1 Like

Ah, yes, forgot all about that. I've revised and replaced the group to use tmp/LT-temp.txt. And tested it, too.

Thanks for the help!

1 Like

it works like magic.
thank you a million mr pasini !

You're welcome! Glad you find it useful.

Mike, thanks for posting this amazing tool. I showed it to a journalist friend about to start a new job, and blew their mind. We just sold a couple more KM copies for Peter :slight_smile:

I believe I have everything installed correctly, but I ran into a bug in 'Emotion Check". It spits out this error repeatedly

Use of uninitialized value in numeric lt (<) at /var/folders/zp/pp7dtsms5mgdtmsz2qz0_56m0000gn/T/Keyboard-Maestro-Script-A50D2931-D590-4C56-9E68-0B07D42CE5AB line 32. 

.
I tracked it as far as the highlighted line in your perl script, but I'm not a perl guy. ("+" just added here, for highlighting)

    for my $value ( @emotions ) {
        print "<p>Sentences with the most <span>&nbsp;$value&nbsp;</span>:</p><ul>";
        for my $sentence ( @{ $opinion->sentences } ) {
+            next if $score{$sentence}->{$value} < $max{$value};
            print "<li>$sentence</li>\n\n";
        }
        print "</ul>";
    }

.
I imagine it's just an unitialized variable. I ran the tool from BBEdit, selecting a page of article text. Other content checks, such as "opinion" and "readability" work fine. I double-checked that I ran this command for installing Opinion

cpanm Lingua::EN::Opinion --sudo
here's a log.
opinion-install-log.txt.zip (987 Bytes)

Thanks for any help you can provide, keeping the 'Emotion Check' in check!

Avi

Thanks for the kind words, Ari.

I've never seen that error message on either the original version or the version for long texts, which both use the same Perl module. I just ran an Emotion check on a 20,000 word file without a problem. It went through eight emotions with high scoring sentences displayed. I also ran it on an InDesign document's text with no problem (which, frankly, surprised me).

The error message doesn't say which side of the < is unitialized.

If we assume there's nothing special about your text, the suspect would be the Perl module itself. I haven't updated it here since Dec. 2018, so that would be v 0.1502, whereas a new install today would be v 0.1600, which involves a lot of "code changes" according to the release notes.

Let's try an experiment.

Replace the line you cited with this line:

       next if !exists $score{$sentence}->{$value} || $score{$sentence}->{$value} < $max{$value};

That change comes from the current example code.

If that solves your problem, I'll roll it into the distribution here. (I tested the code with my version of the module and it works as expected.)

Meanwhile I'll see if, after installing the current module, I can duplicate the issue here. Thanks for pointing it out.

Edit:

The revised example code has one other line that may help chase this down. Here's the entire segment:

for my $value ( @emotions ) {
    next unless $max{$value} > 0;	# new
    print "<p>Sentences with the most <span>&nbsp;$value&nbsp;</span>:</p><ul>";
    for my $sentence ( @{ $opinion->sentences } ) {
 #       next if $score{$sentence}->{$value} < $max{$value};
        next if !exists $score{$sentence}->{$value} || $score{$sentence}->{$value} < $max{$value}; # new
       print "<li>$sentence</li>\n\n";
    }
    print "</ul>";
}

I've commented the two new lines (# new)) and commented out the previous line that causes the error.

1 Like

That worked! - just the single line replacement, I didn't have to try your 2d suggestion. Thanks for the rapid fix.

If it helps to explore the bug, here's the source text, sent with the author's permission ( © Gannet Co.). I got the same results from BBEdit and Pages.
test_article.txt.zip (5.9 KB)

Thanks, that does help a lot. It confirms that the issue is the updated module.

On my installation with the older module (and either version of the code), the report runs as expected. So the new code, which you confirmed works, must be required by the new module.

I'll update the distribution with the new code shortly.

Thanks again for the detective work!

I've just updated the Large File Version above with the new code. And I removed references to InDesign CS5.

I've also added a WordNet Lookup option for a selected word. Undocumented and in beta at the moment as I try to make the report a little more readable than the raw HTML. To use it, select a word before access the command from the palette. The Princeton database will be searched online to retrieve definitions and synonyms.

I just tweaked the WordNet Lookup with 1) a link on the headline word to the Princeton form for deeper exploration and 2) colored examples.