Sometimes you just wake up on a saturday morning with an idea. “I wonder if I can connect to HANA via speech from my Mac”. It would mean I could fire off a request to HANA, get a response back and have the results returned to me via Speech.
Now I have showed you on a number of occasions that can be done on the iPhone by using Siri, but I was wondering how difficult it would be to do it from a Mac. It turns out, it’s a piece of cake.
The first thing I did was look for an ODBC driver for OS X. Now I pretty much expected that we do not have one, but I tried anyway:
And lo and behold, my buddy and fellow mentor Carsten responded. No ODBC driver… Now normally that would have ended my adventure, but as HANA is amongst many things a developers platform, it’s pretty easy to use RESTful services (XS, oData) to connect to HANA. Why would anyone still need ODBC I asked myself:
So with that said, let’s script!
A quick Google shows the Mac has something called “speakable items”. You can use voice commands to have your Mac do whatever you want. Well, that means it can also speak to HANA.
So whenever I say “Mac + a command”, the command is executed and this little fellow will pop up executing my every wish:
How cool is that!
But how do I attach a command to my speakable items? It is simple: AppleScript.
AppleScript is Apple’s own scripting language which can automate a ton of stuff on your Mac. The cool part is that once you save your AppleScript in a specific folder called “speakable items” you can actually trigger actions by voice. Just name the script to a voice command and we should be good to go. The fun starts 😉
First off, I need a JSON parser for AppleScript . As simple Google search gives me one:
It turns out to be a fantastic piece of software which runs in the background waiting for AppleScript to ask it to do something, just like Apple’s own System Events does. A brief look at the samples gives me an idea on how I need to create my script. In the end, 5 lines of code is all I need:
tell application “JSON Helper”
set myRecord to fetch JSON from “http://smartwatchplusapp.appspot.com/temperature” name “admin” password “welcome”
set myResult to |TEMPERATURE| of item 1 of results of d of myRecord as string
say (“The temperature of the HANA Alerter is ” & myResult & ” °C”)
Basically I call JSON helper from my script, I feed it my XS service (the mentioned URL is the XS URL I rerouted to a public domain, the original would look like this: http://126.96.36.199:8000/alerter/services/temperature.xsodata/TEMPERATURE/?$orderby=TIMESTAMP%20desc&$top=1&$format=json), username and password for basic authentication and finally I format the result into something readable. The last step in my script (say) speaks the output of my service. Executing services via speech by voice just became a reality!
I just used one of my services which was still active (from my TechEd HANA Alerter demo). Ofcourse you can do whatever you want with this technology. Any HANA table or view you can make accessible via voice on your Mac!
Below a clip on how it will all look in the end:
Have fun and let me know in the comments which use cases you build! I’m sure you can be tremendously creative.
Thank you for reading and take care,