a lost apple ad?

I’ve been doing a couple of contract jobs over at RentACoder for some extra cashola. One of them involves writing a tool that will convert over 700 MOV files to MP4. Ideally, the user should be able to run the tool, pass in two arguments (source directory and destination directory), be prompted for the export settings (window size, framerate, etc) and then be able to sit back and watch the conversions take place. I learned a few things with this project. For starters, I think Apple needs yet another one of those PC vs Mac ads, and it should go a little something like this:

Mac: I’m a Mac.
PC: And I am a PC.
Mac: Straight outta Cupertino, ya’ll! Hardcore to the Apple-core, biotches!

[PC has a confused and bewildered look on his face]

Mac: I buy my clothes at a wicked store in the mall. See these jeans and this shirt? It looks like it came from a thrift store but they actually cost like $150! Check me out, honeys!
PC: I purchased this suit at a Moores.
Mac: I run Mac OS X.
PC: I run Windows.
Mac: I can also run Windows, but for best results you should use Mac OS X. It’s tight!
PC: I have Microsoft Office.
Mac: I have Microsoft Office too, and it’s all sexy lookin’.
PC: I can integrate Microsoft Office with enterprise apps like SharePoint, BizTalk, Exchange, ERP, CRM and much more.
Mac: Dude, I said I have Microsoft Office. Duh. Who cares about enterprise shmenterprise? There’s like a trillion kagillion wozillion viruses and spyware out there for you. None for me. Nada. Zip. Zilcho.

[Mac high-fives a barefoot and bearded digital artist named Mordecai]

PC: This is true, but I am working on it.
Mac: Aw, man, you always say that. You’re all like “I’m working on it” and I’m all like “yeah whatever, now go get your DirectX on so I can play Prey“.
PC: So I’m not as lame as you say I am, or so it would seem.
Mac: Puh-lease, get over yourself, PC. You show up in ugly brown boxes…boxES. That’s plural, dude. And they’re all cardboard-y and stuff. I arrive in like one box, and it’s smooth and white. You look like you’re from a dirty factory and I look like I’m from another galaxy…or Finland, or something like that.

[A penguin enters and interrupts the conversation]

Penguin: I’m Linux.

[The penguin exits]

Mac: Who’s that guy?
PC: I do not know who that strange-looking fellow was.
Mac: Anyway. I can make movies and music and all sorts of cool stuff that people could post on MySpace.
PC: I also can do that.
Mac: Yeah, but not as cool as me. And your apps don’t begin with a lowercase ‘i’. The ‘i’ means “me” which is “you”. Deep stuff.
PC: Touché. Well played, my good man. However, I make it easy for developers to create software for me. I provide thorough documentation with plenty of examples in multiple languages, and there are many aficionados out there providing help and communities, too.
Mac: Oh yeah?
PC: That’s correct.
Mac: Oh yeah?!?!?
PC: Indeed.
Mac: Yeah…umm…well. I have half-assed documentation for my COM library for QuickTime, none of which resembles structured documentation; it’s more like an extremely brief FAQ at best or a conversation between two programming pals at worst. See what I mean? And I claim that said COM control can reuse serialized export settings in XML format, yet I explode and have yet to provide a fix or explanation, as evidenced here, here and here.
PC: I see. It is surely a pity that you do not provide stellar support for 3rd-party developers like I do.
Mac: But dude, I have a Dock that when you mouseover icons, it’s all “boop-boop-boop”. Rock! Cool! Bling! ‘Sup! No fat chicks! Ummm…give peace a chance? Yeah, that works! Wooohooo! Peace out, homeslices!

Apple makes some nice, albeit pricey, hardware. And Mac OS X is a great operating system. But their documentation for developers needs a lot of work.

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)
comments: 6 »

SendKeys()? meh. how about SendFood() or SendMoney()?

April 1, 2006 under Computers, Programming, Ruby, SendKeys, VBScript

At work last week, it so happened that I had a very tedious manual task to perform. Due to an NDA, I can’t say which server application this task involved. Let’s just say that there isn’t an easy way to import lots values for a picklist field. I had to add 245 values from an Excel worksheet to 3 picklist fields – that would require me to switch to Excel, select the value, copy, switch to the server application, click “Add”, paste, click “OK” 735 times! There is apparently a way to do this by writing a .NET assembly, but I was assured that finding the neccessary info to accomplish this would take longer that actually doing the manual task. And that’s when the thought of my wrists in firey pain from repetive stress foced me to recall and old friend of mine from shell32.dll – the SendKeys() method.

SendKeys() does what it sounds like…it sends keystrokes. Plain and simple. For that task, I knew what keystrokes I needed to do. I could’ve written something in C# or VB.NET, since there’s a SendKeys() method in the System.Windows.Forms namespace, but time was not on my side. There’s nothing like the cling and static-free scripting languages to save the day 🙂 So using the Windows Scripting Host and 15 minutes of my time, I wrote some JScript code (as an aside, it appears that Microsoft is downplaying VBScript more and more all the time) that read all of the values from the Excel worksheet, stored them, and then switched back to the server application’s window to add values in the manual process. I could then take my hands off of the keyboard and watch my “ghost writer” do the work, saving me plenty of time and preventing a repetitive stress injury 🙂

SendKeys() seems old-school to me, but comes in handy when an application you’re working with doesn’t have any of its functionality exposed via COM or .NET or whatever. Even if it does, sometimes it’s quicker to send keystrokes than read API documentation. As a cheesy example, let’s fire up MSCONFIG and automatically switch to the “Startup” tab to see what’s launching when Windows boots:

// Let's get to the good stuff in shell32.dll.
var objWSHShell = WScript.CreateObject("WScript.Shell");
 
// Launch MSCONFIG.
objWSHShell.Run("msconfig");
 
// Wait a couple of seconds for MSCONFIG to launch.
WScript.Sleep(2000);
 
// Switch the focus to MSCONFIG.
objWSHShell.AppActivate("System Configuration Utility");
 
// Keystroke time!
// SHIFT+TAB sets the keyboard focus to the row of tabs.
objWSHShell.SendKeys("+{TAB}");
 
// Hit the right cursor key 5 times to get to the Startup tab.
for (var i = 0; i < 5; i++)
    objWSHShell.SendKeys("{RIGHT}");

Pretty simple, and you don’t need the Windows Scripting Host to use SendKeys() from a scripting language. You can use non-Microsoft languages too. For example, the scripting language that has my attention lately is Ruby – it’s like Python on steroids. This script will do the same thing as the one above, but this time, I’ll write it in Ruby (without comments):

require 'win32ole'
 
objWSHShell = WIN32OLE.new("WScript.Shell")
objWSHShell.Run("msconfig")
sleep(2)
objWSHShell.AppActivate("System Configuration Utility")
objWSHShell.SendKeys("+{TAB}")
 
5.times do
   objWSHShell.SendKeys("{RIGHT}")
end

Think of the fun you can have automating all sorts of tasks in Windows with the SendKeys() method 😉

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)
comments: 0 »