Search code examples
macoswidgetexecutedashboard

OSX Lion Dashboard Widget :: How to execute a shell script


I have this in my (first) OSX Lion Widget.

var test = widget.system("/Users/Me/testscript",null);

test.outputString is undefined and test.errorString is sth. like that

DashboardClient[xxxxx:xxx] *** NSTask: Task create for path '/Users/Me/testscript' 
failed: 22, "Invalid argument". Terminating temporary process.

testscript contains only an echo "here"

As far as I understand via google... NSTask is somehow wrapping my call and it expects an actual executable binary. But, is there a way to execute this bash-script-executable from within a widget just as it is?


Solution

  • In order for a shell script to be called like a binary, it needs a 'hashbang' as the first line of the file:

    #!/bin/bash
    

    which tells the OS which interpreter to use for the script. Without it the OS will get confused about what to do with the file, giving you the error you've seen.