A few days ago i got the spaceNavigator as a present. Although i use both operating systems OSX and Windows i spent most of the time in OSX. Unfortunately the spaceNavigator is not supported widely by mac programs. Therefor i started developing a little cocoa app that makes use of the spaceNavigator. My goal is to use the spaceNavigator in Mac OSX as an extended input device to control different daily tasks. 

There are some different ways to automate tasks in OSX. For this first ‘test’ app i used mostly Applescript. 

Applescript is an powerful and easy language to run simple tasks. 
Let me explain an simple task that selects the next track in iTunes: 

tell application “iTunes”
       next track
end tell

 

Off course selecting a next track is not that useful, although it gives a good view of the simplicity of the basics.

Ok, thats nice we can perform different tasks by writing simple applescript, but how to run them so they become useful?

This is where the 3Dconnexion SDK comes in. The 3Dconnexion sdk supply’s three little sample apps, i’m using the “3DxValuesCocoa” app. This simple app shows you how to use the provided 3DconnexionClient.framework.  For more information look at: http://www.3dconnexion.com/support/sdk.php

i modified the app so it can use an appleScript. Basically i add the folowing code: 

if(state->axis[2] > zUp){

if (pauze == 0){

NSLog(@”bigger than %d”, zUp);

NSDictionary* errorDict;

NSAppleEventDescriptor* returnDescriptor = NULL;

NSAppleScript* scriptObject = [[NSAppleScript alloc] initWithSource:zUpText];

    // next track

// set sound volume to sound volume + 2

returnDescriptor = [scriptObject executeAndReturnError: &errorDict];

[scriptObject release];

if (returnDescriptor != NULL)

{

// successful execution

if (kAENullEvent != [returnDescriptor descriptorType])

{

// script returned an AppleScript result

if (cAEList == [returnDescriptor descriptorType])

{

// result is a list of other descriptors

}

else

{

// coerce the result to the appropriate ObjC type

}

}

}

Let me explain the code, when the device reaches a int value higher than “zUp” the appleScript string “zUpText” i scalled. The zUp and zUpText values can be changed in the User Interface.  The “pause” statement is linked to an NSTimer witch returns every second. Otherwise the action can be called many times at once. One second is an correct interval for this example. 
 
Lets look at the UI.
In this test application you can change the settings for the up – down – Rotate left – Rotate right states.
When the application is selected the functions will not be called, only when the applications runs on the background, all function or better sad, applescripts are called.
default the app does the following.           

Rotate left and right access the workspaces when it reaches the value 200:

workspace to the left:
 
tell application “System Events”
keystroke (ASCII character 29) using {command down}
end tell
 
workspace to the right:
 
tell application “System Events”
keystroke (ASCII character 28) using {command down}
end tell
 
Up access the dashboard when it reaches the value 100.
 
tell application “System Events”
key code 101
end tell
 
Down access expose when it reaches the value 150:
 
tell application “System Events”
key code 111
end tell
 
You can download the sample app and play with your personal settings. Just change the appleScripts in the textfields. Remember that the scripts only runs when the app is running in the background. This is an test appliction and i hope to make it more flexible in the future. As example i hope to make this app to be an “agent” application running in the background, and saves the changes in an ‘prefpane’. Please let me know your feedback. Comments are welcome!
 
download: 3DxClientTest.zip
Be Sociable, Share!