0

I have been messing around with voice commands, but ran into a snag. I am trying to get a terminal command to run but it is not working. The command makes asterisks "snow" fall. This is what I have so far.

tell application "Terminal"
activate
run script "ruby -e 'C=`stty size`.scan(/\d+/)[1].to_i;S=["2743".to_i(16)].pack("U*");a={};puts "\033[2J";loop{a[rand(C)]=0;a.each{|x,o|;a[x]+=1;print "\033[#{o};#{x}H \033[#{a[x]};#{x}H#{S} \033[0;0H"};$stdout.flush;sleep 0.1}'"
end tell

All I get are errors

2 Answers 2

2

Command line scripts executed with the do shell script command. The string escaping can get a bit gnarly, so be careful with that too. Here's a simple example:

do shell script "say \"Today is `php -r \"echo date('l');\"`\""

EDIT:

OK, I just realised your script actually depends on having a Terminal window to run in, so the usual approach of do shell script won't work here.

There are still a lot of unescaped quotation marks in your Applescript, but rather than fixing those, I think it would be easier to put the whole ruby script into a stand-alone file and pass that to Terminal instead.

stars.rb

#!/usr/bin/ruby

C=`stty size`.scan(/\d+/)[1].to_i;
S=["2743".to_i(16)].pack("U*");
a={};
puts "\033[2J";
loop {
  a[rand(C)]=0;
  a.each {
    |x,o|;
    a[x]+=1;
    print "\033[#{o};#{x}H \033[#{a[x]};#{x}H#{S} \033[0;0H"
  };
  $stdout.flush;
  sleep 0.1
}

AppleScript

tell application "Terminal"
   activate
   do script "~/stars.rb"
end tell
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks a lot, but for some reason the script I want to run is still giving me errors, but it runs fine in terminal.
I've edited my answer — please take a look and let me know if it helps.
Aha! And all this time I've been sending them to the Finder. Thanks for that — I'll edit my answer.
1

An easy way to escape a shell command for AppleScript is to save the command in a text file. Run the script below and copy the Result.

set myText to read (choose file) as «class utf8»

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.