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 :)
Related
This might be a bit of a dumb question as I'm new to AppleScript, but I'm trying to run a very simple shell script in terminal using AppleScript. The code I'm currently using is:
tell application "Terminal"
do script "videoLoop"
end tell
but I keep getting the error
-bash: fork: Resource temporarily unavailable
Could I also just type "videoLoop.sh" into terminal using AppleScript?
Any help would be appreciated
If you need it to open a terminal window use something like this:
tell application "Terminal"
do script "/Users/youruser/testdir/hello.sh"
end tell
Else, if you just want it to run the script do something like this:
do shell script "/Users/youruser/testdir/hello.sh"
You need the full path, and your script needs execute permissions.
My examples just echo the standard Hello World text but the same should work for most other scripts provided they're written properly.
I am trying to run a shell script in a MAC terminal. I want to open a new terminal window that will execute the script separate from the program that is running. In Fedora, there is a gnome-terminal command which lets me execute a script in another terminal shell.
Does anyone know an equivalent on MAX OSX and how to use it?
For example say I have a script crazy.sh and I want to call this from a program that is executing but in a separate terminal from the one which is currently executing the program.
I like DigitalTrauma's answer but I found for my use, this worked better
open -a Terminal.app crazy.sh
Thanks for the answers.
One way to do it is to use an xterm instead of a terminal window:
xterm -e crazy.sh
If you want the xterm to stay open after the script completes, use the -hold option to xterm.
But if you really need to do this in a terminal, you can do it with applescript:
tell application "Terminal"
activate
tell application "System Events" to keystroke "n" using command down
repeat while contents of selected tab of window 1 starts with linefeed
delay 0.1
end repeat
do script "crazy.sh" in window 1 -- make sure the path to your script is right
end tell
(Credit to the answer here https://superuser.com/questions/466619/open-new-terminal-tab-and-execute-script)
I have a script that opens up as many terminal tabs as are devices plugged in, then it runs tests on those devices. I would like to clean up all the terminal tabs after my tests are done. I run some things in the background, and I don't know when each process will be done.
How can I check if there are process running in the current tab of terminal?
I plan to do a Command W in AppleScript to kill each terminal command after each tab of terminal has no running processes.
Thanks!
If you use AppleScript, you can check the busy property:
tell application "Terminal"
repeat with t in tabs of windows
if busy of t is false then
do script "exit" in t
end if
end repeat
end tell
exit closes a tab if you set "Preferences > Settings > Shell > When the shell exits" to "Close the window".
One simple solution would be to take each command that you're running in a terminal and append "; exit" (Without the quotes) to it.
For example, if one of your commands was "ls", you would change it to "ls; exit".
Unfortunately, this doesn't work if you want to leave the terminal windows up to see results of what's being displayed. That can be solved by outputting the results of the first commands to some file, though.
Again using the example of ls, you could run "ls >> testfile.txt; exit" to output the results of ls to a file, and then have the terminal window close after it finishes executing.
You can use "jobs" to check if there are any processes running in the background.
I've searched over the web and still can't figure it out.
I apologise if this sounds like a lazy whinging cry for help -- I really am at wit's end with this one.
I have a bash script located at:
/cygdrive/k/Linux Scripts/Scripts/filter.sh
I've copied the Cygwin.bat to filter.bat, and changed it as follows:
#echo off
L:
chdir L:\Cygwin\bin
bash --login "/cygdrive/k/Linux Scripts/Scripts/filter.sh amc.txt bmo.txt"
When I run filter.bat by double-clicking on it in Windows Explorer, the console flashes open momentarily and then closes. The script is OK, because it runs from the command line in the Cygwin console.
Is there a way to debug this problem?
Try running the batch file from an already-existing Command Prompt window so you can see any error messages bash might send. I'm guessing it has a problem with "/cygdrive/k/Linux Scripts/Scripts/filter.sh amc.txt bmo.txt" -- as far as it's concerned, that's one argument rather than three. Therefore I would change it to
bash --login "/cygdrive/k/Linux Scripts/Scripts/filter.sh" amc.txt bmo.txt
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"