Is it possible to execute an rspec command (usually executed in Terminal) using Shoes?
More detailed: I want to create some kind of GUI with a few buttons. Every button should execute a different command usually executed in Terminal.
So, I want to start my Shoes app -> click a button -> the button opens Terminal and executes a command (something like "cd /Users/Documents/test" and then "rspec test_spec.rb". I'm a Ruby and Shoes newbie, so if there is a better/easier way to do this for a newbie - please suggest.
OS: Mac OSX
Thank you!
Shoes is just a ruby program, so you can do whatever ruby does. So this stack overflow question should hold your answers.
For instance this works and returns the result:
2.2.2 :004 > `pwd`
=> "/home/tobi\n"
You can run the commands, capture the output and then display it in your shoes application anyway you like.
Related
I'm currently pulling my hair out trying to make an apple script execute a shell script / Unix executable, so that I can drag it into the dock. I don't have much experience with AS, so this is propably an easy fix for many of you guys.
Here's the whole script:
to run
do shell script "/Users/MyUserName/Documents/cmus/2.7.1_1/bin/cmus"
end run
Cmus is a terminal music program that is a Unix executable.
When I try to run it, I get this error message:
error "Error opening terminal: unknown." number 1
What is the problem? Pls help...
I am guessing your program is curses based and needs a Terminal window, so try this:
to run
tell application "Terminal"
do script "/Users/MyUserName/Documents/cmus/2.7.1_1/bin/cmus"
end tell
end run
#TheUnderBrony don't use do shell script but use do script. do shell script is part of the standard addition.osax which open an shell in the background do script is part of the terminal which will execute the string in a terminal window.- dj bazzie wazzie
This solved my problem, thank you! But Only one slight problem is left: The terminal starts and opens the program, but it opens it in the background, aka, I need to click on the terminal icon to show the window. Do I need to activate the window? If so, how? But already thanks a bunch :)
I believe you can easily reproduce the issue.
Just take a fresh RubyMine (7.1) — either Mac or Windows version, Ruby 2.2, create simple script:
puts "Hi, i'm gonna break your debugger :)"
user_input = gets
puts "Here should be breakpoint"
Put the breakpoint on the 3-rd line and run Debug session (RubyMine uses ruby-debug-ide gem).
When you type something in RubyMine console window for the script to read in gets — program doesn't eat your input saying:
Could not execute statement: current stack frame is unavailable. Pause
the process to use console interpreter
What's going on here and how can you debug such Ruby scripts?
This appears to be a RubyMine quirk. If you disable the console prompt by clicking on the 'Show Console Prompt' icon in the debug pane this should start working as you expect
See attached Screenshot if you are struggling to find the 'Show Console Prompt'enter image description here
I have a command-line Ruby application that uses Curses to create a GUI. This GUI is absolutely mangled by Windows' command prompt if the command prompt window is too small.
The command prompt window can be resized in properties. However, I want to resize it programatically.
Running this command in the command prompt (nothing to do with Ruby) will resize the command prompt window to desired variables.
mode con:cols=120 lines=40
Can I do this purely in Ruby?
Or, failing that (I suspect doing it purely in Ruby may be impossible) can my ruby application actually run that command and 'hit enter', and resize window it's running in?
Ruby has several ways to 'shell out', and there is an in-depth post here on SO about it:
Calling shell commands from Ruby
Hey guys, I run LinuxMint and I have some scripts which I want to run without terminal, can you tell me how?
You need to:
Put as the first line of your ruby script the following shebang line (so bash knows what program to use to run this file)
#!/usr/bin/env ruby
Make your ruby file executable. In a console you can do this:
chmod 700 my_ruby_file.rb
Test that your ruby file is now executable. In a console write:
./my_ruby_file.rb
Notice that we are no longer calling "ruby my_ruby_file.rb", but instead just call the file directly "./my_ruby_file.rb"
If your ruby program executed normally, then everything is going well. If it does not execute and shows you an error, then something is not well done from the previous steps (and post your error)
In your desktop, create an application link, and point it to the my_ruby_file.rb
Once you have the application icon created and shown in your desktop, you can doble-clickit and it will run your application.
Tell us how it went- cheers
I have written a ruby daemon and I would like for it to run when I log in. It is normally run by going to the command line and calling ruby my_ruby_script.rb. How can I start my daemon on login? (Running 10.6 Snow Leopard).
There's an option to add applications etc that need to start at login, you could try writing a shell script or an apple script thing that launches terminal and runs ruby my_ruby_script.rb, or possibly even just add my_ruby_script.rb to this list after adding a #!/bin/env ruby line to the top of that file. http://support.apple.com/kb/HT2602?viewlocale=en_US gives precise instructions as to how to add an application to be started at login.
If you need to use AppleScript to actually start a terminal application (I believe this is not the case, but I am not in front of my mac now and hence can't test), just create an applescript file with something like
do shell script "ruby <path>/my_ruby_script.rb"
Hope this helps
As Panda said, add:
#!/bin/env ruby
to the begining of the file, and then you could add a reference to your file inside ~/.bashrc or ~/.profile or even /etc/profile , depending on your needs.
Check this out: https://stackoverflow.com/questions/3484429/profile-and-bashrc-doesnt-work-on-my-mac/3484472#3484472