尝试从 Widget widget.system() 获取环境变量
我正在尝试编写一些 Dashcode,但在运行 /env 命令时似乎无法获取环境变量。该环境似乎没有来源,因为它总是返回“未定义”。下面是我的代码,我愿意接受任何建议(我需要的不仅仅是 LANG,LANG 只是示例)。
var textFieldToChange = document.getElementById("LangField"); var newFieldText = widget.system("/usr/bin/env | grep LANG").outputString; textFieldToChange.value = newFieldText;
有没有一种简单的方法来获取我的环境并将其缓存在 Dashcode 中,或者我是否需要尝试编写一些以某种方式缓存整个环境的东西?
感谢您的任何想法!
I'm attempting to write some Dashcode to but can't seem to get the environment variables when I run the /env command. The environment doesn't appear to be sourced because it always returns "Undefined". Below is my code and I'm open for any suggestions (I need more than just LANG, LANG is just the example).
var textFieldToChange = document.getElementById("LangField");
var newFieldText = widget.system("/usr/bin/env | grep LANG").outputString;
textFieldToChange.value = newFieldText;
Is there an easy way to source my environment and cache it in Dashcode or do I need to attempt to write something that will cache the entire environment somehow?
Thanks for any ideas!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否允许命令行访问?转到“小部件属性”(在左侧菜单中),然后选择“扩展”并选中“允许命令行访问”,否则小部件将无法与系统通信。但不确定这是否是导致问题的原因。
Have you allowed Command Line Access? Go to Widget Attributes (in the left hand menu) , then extensions and check Allow Command Line Access else the widget is prevented from talking to the system. Not sure if this is what is causing the problem though.
我知道这个线程已经很老了,但无论如何,这个问题仍然是最新的:-)
我自己刚开始使用 Dashcode 和小部件,我对此做了一个快速破解:
对于我的实验小部件,我确实使用了滚动区域和一个按钮。 doGetEnv(event) 在 onclick 时触发,通过检查器设置。 Id“内容”是滚动区域内内容的标准命名。
out var 包含一个带有 '\n' 字符的字符串,使用 split() 将其转换为数组。
在我的例子中,第一个条目是“BASH...”。
如果您搜索特定项目,请使用 STRING 的匹配方法(另请参阅 http://www.w3schools. com/jsref/jsref_match.asp)以及以下有关正则表达式的页面:
要缓存环境,您可以使用:
这将在 envCache 中留下一个数组。选择:
I know this thread is quite aged, but anyway, the question is still up to date :-)
Just having started with Dashcode and widgets myself, I did a quick hack on this:
For my experimental widget, I did use a scroll area and a button. The doGetEnv(event) is fired upon onclick, set via inspector. The Id "content" is the standard naming of the content within the scroll area.
The out var containes a string with '\n' charaters, to transform it into an array use split().
The first entry is "BASH..." in my case.
If you search for a particular item, use STRING's match method (see also http://www.w3schools.com/jsref/jsref_match.asp) along with the following pages on regular expressions:
To cache the environment, you can use:
This will leave an array in envCache. Alternative: