I know there is a Terminal plugin for quicksilver but I would invoke terminal commands which basically just runs in the background and never popups a terminal window. is that possible?
UPDATE:
I have the following code in my applescript but its giving me an error:
do shell script "/path/to/shell.sh blah"
error:
curses.setupterm()
_curses.error: setupterm: could not find terminfo database
In Quicksilver you can use the action "Run Command in Shell", which is part of the "Terminal Module". The command is run without showing a window. Search on the quoted terms and you'll find some examples.
Applescript is the simple solution, see:
http://developer.apple.com/library/mac/#technotes/tn2002/tn2065.html
Sample:
do shell script "ifconfig"
do shell script "ifconfig" user name "Anne" password "p#ssw0rd" with administrator privileges
Automator can also run shell scripts in the background.
If you are familiar with XCode, you can use NSTask with Objective-C.
Hold on a sec, is your shell script a bash shell script? In your first line do you have:
#!/bin/bash
If not, add that line to your script.
Also instead of just
do shell script "/path/to/yourscript.sh"
consider this:
do shell script "/bin/bash /path/to/yourscript.sh"
Related
From my /home/mobaxterm command prompt, I can use the newtab "command" to launch a new tab and execute a command just fine. When I use it inside a bash script, I get "newtab: command not found".
Is there special coding required to use the MobaXterm commandline parameters as found here: https://blog.mobatek.net/post/mobaxterm-command-lines/ inside a bash script?
Thanks.
Use this
/bin/MobaSendMsg.exe MobaXterm -newtab "YOUR_COMMAND"
I'm trying to run a bash script from cmd. When I execute the script a new terminal is opened an immediately closed since there is some problem with it. Because its happening so fast I can't read the problem. I'm looking for a way to keep the terminal open once the script exits.
Go horribly Windows-y with this:
read -p "Press any key to continue" x
You can also put a $SHELL in a new line at the end of your script. The window will stay open, no matter from where you open your shell script (e.g. cmd / powershell / etc).
Add bash at the end of the script
It works for me.
to test a .sh script in windows cmd (assuming you have bash installed and in your path environment variable):
cd into parent directory,
type "bash" to enter bash console,
type "./",
type "exit" to exit bash console
Pretty much as titled. If I were to manually do this, I would first open a Cygwin Terminal (which should be /cygwin/bin/mintty.exe), and then in that terminal, cd to the directory that has the python script, and then execute the python script by doing "python myPython.py". I'm wondering if I can write a batch script or a bash script to do this: start a Cygwin Terminal, cd to a directory, execute a python script in the directory.
Thanks.
Edited:
So I have a python script that generates csv files for activities through mongodb.This script won't function if I run it through windows cmd. I have to run it in cygwin terminal (mintty.exe). So any alternatives to execute the python script won't work. I have to somehow start a Cygwin Terminal and execute the python script through there. Any ideas please? Thanks.
Depending of your needs it could be better to start mintty (creating a new window) instead of starting bash inside the cmd.exe window.
When you want to use ansi escape sequences then it works better with a real mintty window, as the cmd window ignores the escape sequences for window resizing and positioning.
start "" C:\cygwin\bin\mintty --exec ./myProgramToExecute.sh
You may start a bash from the Windows terminal and start your script from there (without starting mintty.exe). Just execute
bash -c "cd /your/directory && python myPython.py"
from the Windows cmd prompt or a batch file.
Ok, I hope this question makes some sense but what is the difference between a bash shell and a bash terminal? Example. When I first open up terminal I have a prompt with my current dir and my user name. In the terminal window header it says -bash- , when I type echo $SHELL I get bash. So by default the shell is bash. Where my confusion comes into play is when I type bash. My prompt then goes to bash-3.2$.Obviously it's a different mode. Are ther any major differences? I have read the man page with no answer. I understand what a bash shell is but just do not get the difference. Thanks for the clarity in advance.
There is no difference, they are both instances of the bash shell.
The reason you are seeing a different prompt is that your initial login shell sources ~/.bash_profile where presumably you have your prompt set. When you type bash it invokes another shell but because this one isn't a login shell, it doesn't source ~/.bash_profile and so you get the default prompt.
If you were call bash -l, (which invokes bash as if it were a login shell) I bet you would see that your original prompt remains
what I want to accomplish is something like the one described in this this question. Basically using AppleScript to send commands to the Terminal.app.
However there's this behavior that I don't want: every command sent using do script directive is echoed to the Terminal. I am currently integrating an AppleScript with Cocoa, and sometimes the software would send sensitive information such as password to the Terminal.
Is there some way to disable this behavior, such as #echo off directive in DOS batch files?
EDIT
To clarify my question, I will elaborate more. Suppose we have an AppleScript such as this one:
tell application "Terminal"
set currentTab to do script "login"
do script "username" in currentTab
do script "password" in currentTab
end tell
I noticed that if the Terminal application is already running, with or without any terminal window open, the commands in the do script directive will be echoed before it is fed to the shell. To illustrate the result of the above script in a Terminal:
Last login: Tue 5 Apr hh:mm:ss on ttys001
login <--\
username <----unwanted echoes
password <--/
<machine>:~ <user>$ login
username: username
password: ****
... (interactive Terminal session)
This doesn't happen however, if the Terminal.app is not running at script execution.
You're "typing" things before the shell has a chance to respond to them (in this case, before login has a chance to turn off echoing). Tools such as expect solve the problem of scripting arbitrary command line utilities, which would be a better solution in the general case, but it's not clear from your question what you're trying to do.
What command are you trying to script, and why are you doing it via Terminal?
To hide the commands in Terminal.app first run this command:
stty -echo
To show the commands again:
stty echo
Instead of using Terminal.app you can also run commands directly from AppleScript:
set theResult to do shell script "cal -y 2011"
Or even better, run the commands directly from Objective-C with NSTask.
(Since your app is using Cocoa I assume it has been (partially) written in Objective-C)