Squeak/Pharo command line scripting

August 9th, 2010 Sean DeNigris No comments

Typical Workflow

I go through a lot of images.  It’s just the way it is – make some changes to a package, try to load it in a fresh image, open another image with an older version to compare.

The Case for Scripting

The frustrating part is not using many images (which is pretty cool – to have multiple computers running at once… but I digress), but setting up the images every time.  So I decided I’d find a way to load common configurations automatically.  But how would I communicate to the image that it should run certain code on startup?  A quick google found writing scripts.

Poor Command of the Mac Command Line

This sounded like just what I needed, but I ran into a bit of trouble with the Mac command line:

~$ open -a /Applications/Squeak\ 4.2.5beta1U
FSPathMakeRef(/Applications/Squeak 4.2.5beta1U) failed with error -43.
~$ open -a Squeak\ 4.2.5beta1U ./Pharo-1.1-scripting/Pharo-1.1-11411dev10.07.1.image
Unable to find application named ‘Squeak 4.2.5beta1U’
~$ /Applications/Squeak\ 4.2.5beta1U ./Pharo-1.1-scripting/Pharo-1.1-11411dev10.07.1.image
-bash: /Applications/Squeak 4.2.5beta1U: No such file or directory
~$ /Applications/Squeak\ 4.2.5beta1U.app ./Pharo-1.1-scripting/Pharo-1.1-11411dev10.07.1.image
-bash: /Applications/Squeak 4.2.5beta1U.app: is a directory

Scripting the Image!

I finally figured out that what I needed to do was call the actual binary inside the .app bundle, so:
~$ “/Applications/Squeak 4.2.5beta1U.app/Contents/MacOS/Squeak VM Opt” ./Pharo-1.1-11411dev10.07.1.image /Users/sean/Squeak/SpdImageSetup.st testArgument
And, bingo!  The image opened and filed in the .st file.  The arguments are available with SmalltalkImage>>getSystemAttribute:  So, for example (in Squeak 4.1), “Smalltalk getSystemAttribute: 3″ returned ‘testArgument’

Running the Script Automatically on Startup

The other thing to know is that you cause the filed in code to run automatically by creating a class>>initialize method somewhere in it, which is run immediately after the code is loaded.
Categories: Pharo, Squeak Tags:

Downloading the Squeak VM

June 16th, 2010 Sean DeNigris No comments

I wanted to download a the latest Squeak Mac virtual machine from ftp://ftp.smalltalkconsulting.com.  I knew that I had to connect as a guest via FTP, but it took a while for me to figure out how to accomplish this (seemingly simple) task.

From what I gathered from forums, Finder is not a good option to get files via FTP (although there seem to be workarounds).  When I tried Terminal, I kept getting a mysterious error (are there any other kinds with computers, lol): “bind: Invalid command `rl_complete’.”  In addition to being totally useless in telling me what was going on, there wasn’t any info online.  Thanks to the fickle gods, the error disappeared just as mysteriously.  The command ended up being:

ftp -a smalltalkconsulting.com

or

ftp anonymous@smalltalkconsulting.com

With the second option, you enter your email address when prompted for a password (this seems to happen automatically with the first one).

The remaining steps were (at the ftp command prompt):

  1. binary
  2. get “Squeak 4.2.5beta1U.app.zip”

And that was that, the file was downloaded into my home directory!

Categories: Mac, Squeak Tags: , ,

Formatting code blocks in a WordPress blog

May 12th, 2010 Sean DeNigris No comments

I haven’t found a way I really love to present code in a fixed width WP layout, but the one I use is workable. It produces code that looks like this:

It uses a <code> inside a <pre> with a scrolling option to:

  • preserve indentation
  • use a special font in a quote box to differentiate from other text
  • provide a scroll bar, as code invariably goes past the fixed width

Here is the code (ironically described inside itself):

<pre style="overflow-x: scroll; padding: 10px;">[Your code here]</code></pre>
Categories: WordPress Tags: , ,

Applescript to change genres in iTunes

May 12th, 2010 Sean DeNigris No comments

There is this awesome programming language in which the entire system (down to the graphics libraries, window system, and compiler) is available to you to reinvent, opening the possibility of truly open computing.

Obviously, I’m talking about Smalltalk. But if you are too afraid to give MS and Apple the bird for not learning (or wanting to learn?) the computing lessons of the 1970′s, there is another option which lets you bend almost any Mac application to your will, breaking it from the chains of presumptuous software giants who think you should work the way they design instead of vice versa.

I’m speaking, of course, of Ruby, lol. If you’re doing any serious Applescript development, ditch Applescript altogether, and check out the rb-appscript library.  It allows you to do anything you can do in Applescript, in a non-ambiguous way, with the power of a full programming language behind you – trust me, it’s the heaven where Applescript will go when it finally dies.

However, if you’re doing something simple and common, especially in a very scriptable application like iTunes, sometimes it’s easier to just crank up AppleScript Editor and hack out a one-liner.

Thus this very simple script to change the genres of iTunes tracks, which I used to fix things like some tracks in the “rock” genre and others in the “Rock” genre.

tell application "iTunes"
  set tracks_to_fix to file tracks of playlist "Music" of source "Library" whose genre ends with "ock"
  set genre of tracks_to_fix to "Rock"
end tell

Fixing URLs after moving a WordPress blog

May 10th, 2010 Sean DeNigris 1 comment

When I moved my WordPress blog, all my image links were broken :(  Fortunately, with a simple google search (mysql replace substring), and 5 minutes of work in phpMyAdmin, everything was right as rain.

I ran the command (adapted from a comment here) on two fields in the wp_posts table - wp_content and guide:

UPDATE wp_posts
SET [insert_field_name_here] =(
REPLACE ([insert_field_name_here],
'[insert_old_URL_here]',
'[insert_new_URL_here]'));

One browser refresh later, I was returned to multimedia heaven :)

Categories: WordPress Tags:

Why Apple and Microsoft can’t touch Squeak Smalltalk

April 27th, 2010 Sean DeNigris No comments

Life in Mac / Windows

Software is hard… and buggy.  We all know that.  Unfortunately, in mainstream systems, there’s very little we can do about it, except maybe file a bug that disappears into the bureaucracy of a major corporation, probably never to be heard from again.

The Squeak Life

I’m using an application called ScriptManager to keep some simple notes.  Here’s a little screenshot:

Now as software is wont to do, as soon as I went to save a profound (and long) note, an error occurred:

“What the heck is that!?” you say.  ”I can get cryptic error messages quite easily in Windows, thank you very much.”  Except, this is no ordinary error message – it’s a debugger opened on the application’s code, so I can see exactly what went wrong.  I can do this because all code – from the lowest level graphics and file libraries, to whole applications – is available to me to change as I please.  And it’s all in the same simple, revolutionary (old) language – Smalltalk.  I don’ have to chase the applications C++ to the libraries’ C to… well what difference does it make – I would’ve given up already.

But in Squeak, within 2 minutes, I had fixed the error and recovered my note.

You see, but flipping through the call stack, the debugger showed me exactly which object had gone south.  I was able to open and inspect this object in another tool:

It was immediately obvious that a nil entry had been stored in a set, which is not allowed.  Right in the tool, I was able to delete the key:

And I was back on track – no work lost!  How does that compare to your last error in OS X or Windows?

n.b. I was using a variant of Squeak called Pharo.  All this info applies to all versions of Squeak.

Categories: Smalltalk Tags: ,

BDD in Squeak Smalltalk: An exploration

April 27th, 2010 Sean DeNigris No comments

Coming from Ruby, I’m obsessed with Behavior Driven Development.  The community (e.g. Rspec, Cucumber) is alive, and there is a body of practices to follow.

Since TDD was born in Smalltalk, I expected to find the same energy and guidance in Squeak.  Squeak represents the most profound, empowering environment I’ve ever seen (I will never go back to C, C++, or even Ruby – which misses the boat by not being a living system).  However, the testing situation seems frozen in the early days.

My intention is to create do a series of experiments, which will lead to BDD best-practices in Squeak.  My vision is code that is pulled into existence by what matters to its users, that is easy to understand, and easy to change.

I’ll keep you posted…

Squeak 4.1 Docking Bar

April 23rd, 2010 Sean DeNigris No comments

I love that every new feature of Squeak is there… And, I love being able to turn them off!

When I’m working, I absolutely must, must, must have a blank canvas, so I don’t like backgrounds, icons, desktops, menus, or anything else to distract me.

To turn the Docking Bar on and off, there is a preference. Go to World menu -> Appearance -> Preferences, and type ‘dock’ in the search field and it will come up.

If you want to toggle the dock on and off a lot, you could save the following code and assign a keyboard shortcut to it:

TheWorldMainDockingBar showWorldMainDockingBar:
TheWorldMainDockingBar showWorldMainDockingBar not.
Categories: Uncategorized Tags:

Adding Quicklook support for Ruby files with different/no extensions (e.g. rake files)

March 4th, 2010 Sean DeNigris No comments

1. Download the excellent qlcolorcode bundle from Google Code

2. Add the following line to QLColorCode.qlgenerator/Contents/Info.plist:

<string>public.data</string>
So that it looks like this:
3. In QLColorCode.qlgenerator/Contents/Resources/colorize.sh, add (and customize) the highlighted code, which you can get at github:
4. Oops!  Forgot, you may have to sudo touch /path/to/QLColorCode.qlgenerator for changes to take effect
Categories: Mac, Ruby Tags: , ,

Quicklook any plain-text file e.g. HAML or ERB

March 3rd, 2010 Sean DeNigris No comments

I’m often jumping from file to file in Rails, so I really wanted Quicklook support for my template files.  Unfortunately, the suggestions I found online were confusing and incomplete.

Here’s a really easy way to get it done – but no syntax highlighting :(

1. Show the contents of TextEdit’s package

2. Open Info.plist in a text editor… like TextEdit, perhaps… hmm…
3. Anyway, add the following snippet (find the code on github):


Put it just before the following section:

4. Customize
  • UTTypeDescription - put in description of your choice (although you probably don’t need to)
  • UTTypeIdentifier – apparently (and this is what was missing from other descriptions), you just make something up here
  • public.filename-extension – add as many extensions as you want to map to this file type
5. Gloat

Categories: Mac, Rails, Uncategorized Tags: , , ,