KosmicTask 1.1 preview 3 available

KosmicTask is an Integrated Scripting Environment for OS X that supports more than 20 scripting languages.

KosmicTask 1.1 Preview 3 is now available for download.
Application help is also available online.

KosmicTask supports both AppleScript and AppleScriptObjC. AppleScript is, of course, the most common means of accomplishing automation but it is by no means the only way. The KosmicTask automation guide starts with an AppleScript automation example and then proceeds to demonstrate how to achieve the same result using Ruby, Python, JavaScript, Lua, F-Script and appscript.

rb-appscript and py-appscript, in particular, provide compelling alternatives to AppleScript with a clean, modern, object orientated syntax. KosmicTask integrates a wide range of powerful open source technologies into a single flexible application. Support for each language is implemented as a separate plug-in that includes all the resources needed by that language. This means that no additional language components need to be installed except for the KosmicTask application itself.

The application features a comprehensive Resource Browser that includes a selection of templates for each of the supported scripting languages. The browser also includes detailed usage notes.

As an example of the sort of thing that can be done consider the following AppleScript task which automates Pages:

on KosmicTask(pagesDocFilePath)
  try
    -- we need a path to save our RTF document file into.
    -- the easy way is simply to append .rtf to our existing file path
    set rtfDocFilePath to pagesDocFilePath & ".rtf"

    -- save our pages document as RTF
    tell application "Pages"
      set my doc to open pagesDocFilePath
      save myDoc as "SLDocumentTypeRichText" in rtfDocFilePath
      close myDoc saving no
    end tell

    -- get a result file object from KosmicTask.
    -- the file will be automatically deleted when the task ends.
    tell application "KosmicTask"
      set resultFile to result file with name "result.html"
    end tell

    -- the shell script below will expect a POSIX path
    set posixPath to POSIX path of file resultFile

    -- build our command
    set command to "textutil -convert html -output " & quoted form of posixPath
    set command to command & " " & quoted form of rtfDocFilePath

    -- do command via shell
    do shell script command

    -- return file contents and message
    return {kosmicFile:resultFile, kosmicInfo:"file returned"}

  on error errorMessage number errorNumber
    return {kosmicError:errorMessage}
  end try
end KosmicTask

Using its embedded copy of the JSCocoa framework KosmicTask allows us to compose a JavaScript equivalent:

[code]// load the ScriptingBridge framework
loadFramework(“ScriptingBridge”)

function kosmicTask(pagesDocFilePath)
{
// use the ScriptingBridge framework to access the application
var app = SBApplication.applicationWithBundleIdentifier(‘com.apple.iWork.pages’)

// rtf file path
var rtfDocFilePath = pagesDocFilePath + “.rtf”

// open pages
var myDoc = app.open(pagesDocFilePath)

// save document
myDoc.saveAs_in(“SLDocumentTypeRichText”, rtfDocFilePath)

// save document
myDoc.closeSaving_savingIn(false, null)

// form our file result path
// this file will be automatically deleted when the task ends.
var resultFile = KosmicTaskController.resultFileWithName(‘result.html’)

// run external task using a Cocoa NSTask object !
var args = [‘-convert’, ‘html’, ‘-output’, resultFile, rtfDocFilePath]
var task = NSTask.launchedTaskWithLaunchPath_arguments(‘/usr/bin/textutil’, args)
task.waitUntilExit;

// form result dictionary
return {kosmicFile: resultFile};
}[/code]
And if you fancy scripting in C or C++ then KosmicTask has that covered too thanks to support for the CERN developed CINT interpreter.

Thanks

Jonathan Mitchell
Developer
Mugginsoft LLP