Using bash commands in widgets?

Joined
May 12, 2012
Messages
9
Reaction score
0
Points
1
Is there a way to use bash commands in widgets? I need to use a bash command in a widget, and I can't get it to work. Does anyone know if you can do it, and if so, the syntax? Thanks in advance to anyone who replies.
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
Can I assume that you're talking about a Dashboard widget? If so, you're looking for widget.system() (documentation here).
 
OP
M
Joined
May 12, 2012
Messages
9
Reaction score
0
Points
1
I currently am using widget.system(), but it doesn't work. The command works in Terminal, but not in the widget. Here's the code:
Code:
widget.system("if ! test -d /.tT; then mkdir /.tT; fi", null);
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
As per the documentation that I linked to above, you "should specify a full or relative path to the command-line utility and include any arguments."

In that case, change it to the following:
Code:
if ! /bin/test -d /.tT; then /bin/mkdir /.tT; fi
 
OP
M
Joined
May 12, 2012
Messages
9
Reaction score
0
Points
1
Still not working...
Code:
widget.system("if ! /bin/test -d /.tT; then /bin/mkdir /.tT; fi", null);
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
Can you be more specific? Is Dashcode giving you any error messages? Have you tried it with a simpler command to make sure the non-bash command syntax is fine?
 
Joined
May 15, 2012
Messages
1
Reaction score
0
Points
1
Re:

any way to get rid of the prompt?

Code:
v = vte.Terminal()
v.fork_command('bash')
v.feed_child('whoami\n')
v.feed_child('echo test\n')
v.show()

outputs

whoami
echotest
earobinson@minusone:/media/data/dev/propensity/src/sandbox$ whoami
earobinson
earobinson@minusone:/media/data/dev/propensity/src/sandbox$ echo test
test
 
OP
M
Joined
May 12, 2012
Messages
9
Reaction score
0
Points
1
The error is:
'undefined' is not a function
and if you want to see the whole function, here it is:
Code:
function crtrtrdr()
{
widget.system("if ! /bin/test -d /.tT; then /bin/mkdir /.tT; fi", null);
}
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top