简体   繁体   English

OSX Lion Dashboard Widget ::如何执行shell脚本

[英]OSX Lion Dashboard Widget :: How to execute a shell script

I have this in my (first) OSX Lion Widget. 我在我的(第一个)OSX Lion Widget中有这个。

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

test.outputString is undefined and test.errorString is sth. test.outputString未定义,test.errorString是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" testscript只包含一个echo "here"

As far as I understand via google... NSTask is somehow wrapping my call and it expects an actual executable binary. 据我所知,通过谷歌... NSTask以某种方式包装我的调用,它期望一个实际的可执行二进制文件。 But, is there a way to execute this bash-script-executable from within a widget just as it is? 但是,有没有办法从小部件内执行这个bash-script-executable呢?

In order for a shell script to be called like a binary, it needs a 'hashbang' as the first line of the file: 为了像二进制文件一样调用shell脚本,它需要一个'hashbang'作为文件的第一行:

#!/bin/bash

which tells the OS which interpreter to use for the script. 它告诉OS哪个解释器用于脚本。 Without it the OS will get confused about what to do with the file, giving you the error you've seen. 没有它,操作系统会对如何处理文件感到困惑,给你看错了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM