!Electronic || !Bionic || !Ultrasonic

From other programming language I know a interesting feature; the ‘with’ keyword. It allows to write some code in the environment within the bindings of the passed object.

Ruby has myriad of ways of doing something and leaves you plenty of freedom to choose your style. I wanted a more readable coherent approach for such an important feature I use all the time.

Read more…

Due to some really bad behavior of some unknown people this site was down from 01:00am to 10:00am. This kind of trouble is inevitable with a low, little, tiny budget as mine is *sniff*

But everything is up and running again. Thanks to the incredible, the fast and very accurate support of MT!

Chinese philosophy sounds really neat to western ears.

So it is that existence and non-existence give birth the one to (the idea of) the other.
by Lao-Tse.

In this spirit of duality, comes two little spheres, the baoding balls.

Read more…

Quicktime

Quicktime

Flatten Movies is an Automator action to flatten every movie Quicktime is able to open. This is a minor release that should improve the responsiveness and stability of the action. Version 1.0 didn’t save the output folder in the workflow, application or plugin this is now working.  Head to the Download Page.

Here is the pursuit of a series of related articles started by Ruby Inox Part1 where I set out to accomplish every task set by the creator. Promptly followed by his first instructions of implementing a simple Point class.

Althought I left out to publish on this site the specification and implementation of the Size class and Rect class, as they are very similar to that of the Point class; you can find the source on GitHub.

Let’s jump straight to the next challenge: Actions

Read more…

A lot going on and increasing. I didn’t imagine to get such respond in as little as one week. Two thousand downloads and still climbing. That was proof enough for me that I procrastinated for to long.

Here is what changed the last couple of days:

Read more…

The main challenge for organizing a blog is oneself desire to overdoing everything. When one has to many ideas flouting around, it is hard to start writing and nearly impossible choosing the categories in advance. After a few posts the direction of the site becomes clear.

Read more…

As requested here is one possible way to convert doc and docx files to pdf using Automator. A word of caution; I successfully converted simple documents but not complex ones. Some application has better support for the doc format than other and Word will always be one step ahead, I think they want it that way? So if you really need the best conversion of complex documents you are forced to stick to Microsoft Word.
Read more…

PDF

PDF

A minor update for a developer a major improvement for a lot of users. I would like to thank for all the feedbacks I’ve got, for Version 1. It had quite a few problems; important enough to be immediately addressed.

What changed

  • A more clean, robust source code.
  • Added a requested feature: to be able to choose the source folder(of the input file) as the destination folder.
  • Fixed a path error by properly escaping the file string.
  • It works now in the temporary folder, so no more files flashing around.

Download Version 1.1

No need for additional software on Mac, if the software we already have is maintained, to succeed in performing virtuously tasks.

Download Convert To PDF

Ruby Dopamine

Here is still the Automator Ruby code that accomplish the painful task of batch processing files to PDF. It got a little bit longer, but can handle bug tracking better that way. It was a mess to figure out what kind of string; escaped or not, cupsfilter would expect.

require 'tmpdir'
require 'fileutils'
 
ARGF.each do |f|
 
  #
  # Input file
  #
  input_file = f.chop # get rid of the newline charachter
  input_file_extension = File.extname(input_file)
  input_file_basename = File.basename(input_file, input_file_extension)
  input_file_name = "#{input_file_basename}#{input_file_extension}"
  input_folder = File.dirname(input_file)
 
  #
  # Final output folder
  #
  if ENV['same_folder'] == '1' then
    output_folder = input_folder
  else
    output_folder = File.expand_path((o = ENV['output']).nil? ? "~/Desktop" : o)
  end
 
  #
  # Final output file
  #
	output_file_name = "#{input_file_basename}.pdf"
	output_file = File.join(output_folder, output_file_name)
 
  #
  # Temporary input/output file
  #
  # cupsfilter doesn't handle well filenames with latin-1 encoding.
  # tried to escape the filename but doesn't help cupsfilter
  # require to work on a copy with ASCII encoding.
  input_copy = File.join(Dir.tmpdir,'original.cupsfile')
  temporary_file = File.join(Dir.tmpdir,'converted.cupsfile') 
 
  #
  # Execute cupsfilter
  #
  FileUtils.copy(input_file, input_copy)
  `cupsfilter "#{input_copy}" 2> /dev/console > "#{temporary_file}"`
  FileUtils.remove_file(input_copy) if File.exists?(input_copy)
 
  #
  # Check if cupsfilter converted successfully
  #
  if $?.success? then
    FileUtils.mv(temporary_file, output_file)
    puts output_file # return the new file to automator
  else
    FileUtils.remove_file(temporary_file) if File.exists?(temporary_file)
    $stderr.puts "Cannot convert #{input_file_name}"
    exit 1
  end
end

Alright, the journey begins. I received the first specification! If you don’t know what this is about perhaps you missed out the story. The first part of the story nor the sotry itslef is relevant for understanding the code that follows. Just a way to keep it interesting and mysterious, until something working comes out of box. Now let me continue the story:

First the creator explained me that after years of debate he settled down on ruby as language for Inox. He then asked me to implement a Point class. At first I objected as why such a class would be of any use and why not represent a point as an array [x, y].

Read more…