My first Cocoa App…

…built using AppleScript Studio is an unambitious but useful graphical XML-RPC client/debugger. The entire app is written in exactly 78 lines of AppleScript code. If that’s not RAD development…

It’s not much… it lacks polish, and it’s not very full-featured. But somebody out there might find it midly usefull. Basically, the suitably-named “XML-RPC Client” allows you to point at an arbitrary XML-RPC service URL available on the network, specify a method and (limited) parameters, and view the response in a readable display. It’s pretty much meant to be used as a handy, graphical debugger for developers setting up or accessing XML-RPC services. I kinda needed something like this at work, and was tired of using the command line for something for which there should be a nice little graphical tool.

Usage is easy… type the URL of the web service you wish to access in the first field (e.g. http://superhonker.userland.com/rpc2. Type the method name into the second field (e.g. examples.getStateName). Type the parameters in literal pseudo-code in the third field (e.g. 18). As far as the parameters go, strings will generally be recognized as strings, ints as ints, reals as doubles, and true and false as bools. Pretty straight-forward. For example, the parameters tod,27,true,2.3 would automatically be recognized as being of type string, int, boolean, and double. You can optionally enclose strings in quotes, but it will make no difference.

There’s still work to be done. At this point, you can only send arguments of some of XML-RPC’s “primitve” types: string, int, double, and boolean are supported. structs, arrays, base64 and dateTime.iso8601 are not. That means that you may not access any service methods requiring parameters of those types using XML-RPC Client. Release early and release often, right?

XML-RPC Client is freely available, and I’ve posted the AppleScript below. Anyone wishing to help me get support for more XML-RPC datatypes just shoot me a line with the patches.

Dowload XML-RPC Client (124 kb)

XML-RPC Client screenshot

I’ve been tinkering with Cocoa for a couple of weeks now, and I’ve quickly fallen in love. The only other GUI toolkit I’m experienced with is Swing… and while I think Swing is an excellent API, I’m beginning to have a feeling that I’m going to prefer the Cocoa development experience. With Swing, the Java language is the shining jewel of the framework. Java is mature, rock-solid, secure, robust, dynamic and easy to write. In Cocoa, I personally feel that Interface Builder is the defining feature. I haven’t seen a Swing GUI builder that even comes close to Interface Builder. In fact, I’d been so unimpressed with Swing GUI builders in the past, that I wrote the whole idea of GUI builders off as nonsense.

Interface Builder has completely changed my mind.

Wow, you can pull together a fantastic-looking GUI and bind the interface widgets to properties of your Objective-C or AppleScript domain or controller objects in minutes. Again, the Cocoa development experience is fabulous.

Neither Objective-C nor AppleScript really compare to Java as far as languages go, but in the overall experience, this is more than made up for by the ease of development. Overall, I find the Swing API to be a bit more sensible and complete (if not more complex) than the AppKit Framework (the Cocoa equivalent API), but I may be a bit biased and/or uninformed there… Of course, Swing still has the advantage of running on all major platforms…


-- XML-RPC Client.applescript
-- XML-RPC Client

--  Created by Todd Ditchendorf on 7/30/05.

on clicked theObject

    set win to window "main"
    my setProgress(true)
    set theUri to (get the contents of text field "uriField" of win) as string
    set theMethod to (get the contents of text field "methodField" of win) as string
    set theParams to (get the contents of text field "paramsField" of win)
    set theParams to my parseParams(theParams)

    try
        my displayResult(my execute(theUri, theMethod, theParams))
    on error e
        my displayResult(e)
    end try
    my setProgress(false)

end clicked

on execute(theUri, theMethod, theParams)
    using terms from application "http://apple.com/placebo"
        try
            tell application theUri
                set theResult to (call xmlrpc {method name:theMethod, parameters:theParams})
                return theResult
            end tell
        on error e
            return "Unsupported method or URI"
        end try
    end using terms from
end execute

on displayResult(theResult)
    set theView to text view "resultTextView" of scroll view "scroller" of window "main"

    -- hack to convert a record to a string. anyone know how to do this properly?
    try
        theResult as string
    on error e
        set text item delimiters to "Can't make "
        set theResult to item 2 of text items of e
        set text item delimiters to " into type string."
        set theResult to item 1 of text items of theResult
        set text item delimiters to ""
    end try

    set the content of theView to (get the contents of theResult) as string
end displayResult

on setProgress(val)
    set prog to a reference to progress indicator "spinner" of window "main"
    if val then
        tell prog to start
    else
        tell prog to stop
    end if
end setProgress

on parseParams(input)
    set text item delimiters to ","
    set toks to get every word of input

    set len to length of toks

    repeat with i from 1 to len
        set tok to item i of toks
        --coerce bools
        if "true" is equal to tok then
            set item i of toks to true
        else if "false" is equal to tok then
            set item i of toks to false
        else
            --coerce ints and reals
            try
                set item i of toks to tok as number
            end try
        end if
    end repeat

    return toks
end parseParams


About this entry