Monday, December 28, 2015

Quick and Dirty OCR on OS X for Free

Wait, Stop, Don't spend that $80+ on some fancy OCR software just yet.  There are some free open source tools out there and with a bit of work you can have very functional workflow using them and OS X. This guide will help you set up an applet you can drop images onto to OCR them to plain text.  This will not create PDF's, formatted, or indent documents, but rather just one large text block that is structured the same as the source text with line breaks.  The following tools are used, but instructions are provided below so you don't need to download anything from the sites.
  • Homebrew The missing package manager for OS X
  • Tesseract Open Source OCR Engine
  • Automator

Install Tools

First off lets install Homebrew to simplify managing custom packages.  This will keep everything in a special /usr/local/ directory so it won't interfere with OS X's normal system.  To do this open up the Terminal application, copy and paste the following command, and press Return to execute it.  You will be prompted to authorize the installation and may be asked to install some OS X command line tools directly from Apple.

ruby -e "$(curl -fsSL"

Next we need to install Tesseract and some supporting libraries.  Again int he Terminal window enter each of these lines and press Return to execute them separately.  They may take a few minutes to compleate before the command prompt returns.

brew install imagemagick
brew install tesseract --all-languages

Configure Applet

Next we need to create a user friendly way to do the OCR.  We can easily do this with Automator in OS X.  Open Automator and create a new Application.  On the left search for and add Run Shell Script and Display Notification in order.  In the Run Shell Script change Pass input to as arguments add the following code to that step.

for var in "$@"
convert "$var" -resize 400% -type Grayscale - | tesseract -l eng - - | pbcopy 

As an alternate the following code will convert the entire result to a single line of text if that is preferred, but it may cause issues if there are columns of text on the image.

for var in "$@"
text=`convert "$var" -resize 400% -type Grayscale - | tesseract -l eng - -`
echo $ocr | pbcopy

Next add some text to the notification step so you know when the task is done processing.  I added a title of "ORC Finished" and a message if "Text was copied to your clipboard.".  Then just save the application and give it a name.

Using the Applet

To use the applet first fine it and d rag it down to your Dock to make a shortcut.  Then you can drag image files onto the application in the Dock and it will do it's magic.  Once you drop an image onto the Applet it will take a few seconds to process and you should see the notification pop up when it is done in the corner.  At this point you can past the resulting text into a program of your choice, clean it up, and so what you want with it.

Other things that can be done with a bit of tweaking to the above scripts:

  • Processing multiple input files at once.
  • Saving results to a text file on the desktop or source folder instead of the clipboard.
  • Opening the resulting file automatically.
  • Remove the notification step if desired.
  • Create a Folder Action instead to automatically run on files added to a specified folder.
  • Advanced tesseract options can be passed in the script but in my experience these were not needed.

Friday, December 4, 2015

Bookmarklet to Post to Slack from your Bookmarks Bar

I use Slack, and one think me any my friends love to do is share new articles and discuss them.  But the good old copy and past the link was annoying me, so I created a Bookmarklet that will share your current page to a selected channel.  Just go to the following page and follow the instructions to build your own widget.  

For peace of mind a brief overview.  This bookmarklet is purely javascript and no data is posted to any other servers besides the slack Webhook to receive the post.  The tool linked above is also curly javascript to build and customize the widget.  It will ask for your Webhook URL but it does not post or track anything and simply embedded that URL in the widget it present to you.  The URL only exists in your widget and this builder tool records no data whatsoever.  The fact that it "remembers" your settings is simply done by updating the URL with a search hash which also isn't sent to the server.

Monday, October 19, 2015

Fix for Pillars of Eternity Blank Screen on OS X

Here is a quick fix for the blank/non-responsive screen in when going full screen in Pillars of Eternity on OS X (El Capitan). Note that you will have to do this before you run the game each time as it will reset the settings with bad ones each launch.
  • First open up the game and take it out of Full Screen mode if it in that mode.
    • Press Command+F to take it out of Full Screen.
    • Exit the game or press Command+Q.
  • Press Command+Space to start Spotlight Search.
  • Start typing Terminal and launch the Terminal application.
  • Copy the following text as a single line into your clipboard.
defaults write "unity.Obsidian Entertainment.Pillars of Eternity"  "Screenmanager Is Fullscreen mode" 0 && defaults write "unity.Obsidian Entertainment.Pillars of Eternity"  "Screenmanager Resolution Width" 2560 && defaults write "unity.Obsidian Entertainment.Pillars of Eternity"  "Screenmanager Resolution Height" 1440
  • Click over to the Terminal window and Past the copied text.
  • Press Enter to runt he command.
  • Launch the game as normal.
Somewhat inconvenient granted; you could make a script to do it but I don't want to post any executable code online.  Also this above code will not require a password or generate and output when executed even though it works.

Also, you may need to change the width(2560) and height(1440) if your native resolution of your monitor is different.

Thursday, October 8, 2015

Making Time Based Graphs with Chartist

I have been implementing some custom charts with Chartist recently.  Overall things have gone very well with some simple tweaks and fiddling to get things exactly how I want.  It is very nice to be be able to easily adjust the charts with CSS right in the normal site code.

The only problem I had was using Date based charts that don't have fixed intervals.  If the Dates or Times are at a fixed interval you can just write the values directly to the labels variable and format them how you want very easily.  If you have a random or variable set of dates, say when inventory is logged which is done at a random, there is no easy way to graph this and keep the relative positions correct on the graph.  I don't want all the points one unit apart, as one could be two weeks and the next 2 months, but rather properly positioned based on the date provided.

Anyway, I got it to work and where is a brief example/sample code to try out.
As you can see in the sample here the items are positioned properly.

Friday, October 2, 2015

Problems with Java Based OS X Applications Hanging when Entering Text

So I found another problem with my new upgrade to OS X 10.11.  That is that the Java web application I was using, Adobe Ad Hoc Analysis in this case, would hard lock every time i tried to enter text in a text box.  The only solution was to force quit the application.  After much testing I found the culprit was the RescueTime helper applet.  Basically this applet gets Accessibility access so that it can inspect windows and record time used but is glitching on the java windows and causing the lock up.

There could be other programs causing the same issues even if you don't use RescueTime but are having the same problem.  To troubleshoot do the following.

  • Close out of the java program that is locking up.
  • Open System Preference > Security & Privacy > Privacy > Accessibility.
  • Note with items are check and then uncheck them all.
  • Restart your java program and attempt to reproduce the issue.
  • If it is working correctly then quit, re-enable one item, and try again until you find the culprit.
  • If you can't get around the error even with all Accessibility options off that you must have some other issue.
Anyway if you find any items fix the problem you can just leave them off though they might hinder there applications functionality.