Alvin Alexander | Java, Scala, Unix, Perl, Mac OS X

AppleScript iTunes FAQ: Can you demonstrate an AppleScript iTunes example (such as an AppleScript iTunes alarm clock)?

For a little while now I've been creating an AppleScript iTunes alarm clock application (an AppleScript alarm that would work with iTunes). The basic idea of the application was to do the following:

AppleScript time subroutine FAQ: Can you share an example of an AppleScript subroutine (function) that returns te current time?

Here's an example AppleScript subroutine (also known as a function or method) that returns the current time as hours and minutes, along with the AM/PM modifier. For the purposes of creating an alarm clock AppleScript program, I didn't like the default format of the AppleScript current date command, so I use this method to extract the current time information I want.

Still reading Calculus Made Easy, they note that 'e' (the natural logarithm, or natural log) is the limit of the following series:

1 + 1/1! + 1/2! + 1/3! ...

To test this I created the following Ruby natural log program.

AppleScript result output FAQ: How can I display the output of my AppleScript script (the AppleScript result)?

Cool, I just learned how to get AppleScript output to show up in the ScriptEditor Result tab. In short, just leave a string at the end of your AppleScript script, and it is printed in the ScriptEditor Result tab.

ScriptEditor Result output: An AppleScript output "Hello world" example

Here's a quick AppleScript result example that puts "Hello world" in the ScriptEditor Result tab:

AppleScript dialog list FAQ: How can I display a list in an AppleScript dialog?

I couldn't find an example showing how to display a list of strings in an AppleScript dialog, so I created the following simple example. First I create a list (in this case a short list of voices on Mac OS/X that can be used with the say command), and then I display the list in a dialog the user can use to select one of the items in the list.

AppleScript alarm clock: Creating a time-based trigger.

I'm still working on my AppleScript iTunes alarm clock program, and looking for a way to set the alarm clock wake up time from the script itself. Earlier I was thinking about doing this using the Mac crontab facility, but somehow I don't think that's going to work for everyone. :)

Mac text to speech voices: What do you know about Mac OS X text to speech voice capabilities, including using AppleScript to convert text to speech?

I'm goofing around currently, using the very cool Mac text to speech capability. Okay, really, what I'm doing is writing an AppleScript iTunes alarm clock program to wake me up in the morning, and in the process I started digging into this Mac text to speech stuff, using AppleScript.

A couple of us were just working on a Java application that uses a JDialog, and were wondering how to change the icon image of a JDialog (a Java dialog).

Changing the JDialog icon image doesn't seem to be too hard, though it's not quite as simple as you might think. It turns out that the JDialog inherits the icon image from it's parent, which in my case is a JFrame. So in the code sample below I'm showing two different ways to do this.

I just ran into a situation where I needed to import some CSV data into a MySQL database table. I already had the data I needed in a CSV file format, and I needed to import the data in that file into my MySQL database table.

A few more specifics about the problem and the solution:

Secrets of Apple design: A Steve Wozniak quote on designing products to work the way humans work.

I wrote recently that for some areas of design, we need to get away from thinking like humans -- with our inherent physical limitations -- if we're going to make the next great inventions. (That article is no longer available, but it consisted of excercises like getting down on the floor, and looking at the world from the perspective of a child or a small animal; or standing on a desk, and seeing what things would look like if you were 10' tall.)

A friend of mine mentioned something the other day that has resonated with me quite a bit. I don't remember who he was talking about -- a person in the military I think -- but he mentioned that this person went through interesting lengths to remind himself each day that we see the world through a narrow lens.

If you ever see the following error message when running a Ruby mail script that uses the IMAP library it may not be as bad as it seems:

Here is the source code for a Ruby mail program I wrote that looks through my INBOX and finds all the email messages I have a) read but b) have not replied to.

This Ruby script comes in very handy on a project I'm working on now where we exchange 50-75 email messages per day. After a little while there are so many messages I can't remember if I replied to the important messages, so this program helps whittle down the list and just shows the ones I have read, but have not replied to. (The ones I haven't read are a lot easier to spot.)

Here's a Ruby mail program that I use to read my inbox, and move mail messages from a group of people that I have read to an IMAP folder that I have setup specifically for those people. The beauty of this is that I don't move the email messages I haven't read yet -- I just move the messages I have read.

Mac Java FAQ: Where is Java installed on my Mac OS X system?

On Mac OS X 10.10 (Yosemite), you can find Java installations under this directory:

/Library/Java/JavaVirtualMachines

I currently have versions of Java 7 and Java 8 installed under that directory.

On much older versions of Mac OS X — like 10.4 — Java versions used to be installed here:

/System/Library/Frameworks/JavaVM.framework/Versions

I was recently reminded of the danger of leaving less-experienced software developers alone to create new functionality in a technical area where they have no prior experience. For instance, suppose you have one or more good but less-experienced developers, and you ask them to work in a technical where they have no prior experience. These aren't totally inexperienced developers; they may each have at least five years experience. Given that their are other people on the team with experience in this area, how do you think this should be handled? Choices include:

tar gzip FAQ: Can you show how to extract (un-tar) a tar archive that has been created with tar and gzip?

Say you have a file (archive) named myfile.tar.gz, and you want to unzip it and unpack (un-tar) it in one command. This "tar extract" command should do the trick for you:

tar xzf myfile.tar.gz

That tar command can be read as "use tar and gzip (the 'z' option) to extract the contents of the file (archive) named myfile.tar.gz.

No real introduction here today, just some sample Ruby code I want to have out here so I can remember some syntax for using Ruby to connect to a MySQL database.

In particular I am also using the here document syntax to simplify the writing and reading of a long database query.

Linux wget FAQ: Can you share an example of the Linux wget command?

Suppose you're working on a Unix or Linux machine remotely through an SSH session, and then you need to get a resource (like a tar or gzip file) that's on the Internet over to that machine. You could download that file to your local machine, and then use scp to copy it to your remote Unix box, but that's a lot of work.

Here's a quick look at a "Ruby DB2" program I created to read data from a DB2 database table on an AS/400 (iSeries) DB2 database.

My Ruby DB2 ODBC example program

First, here's the example Ruby program that accesses the As400 DB2 database, with a few names changed to protect the innocent: