Question

I need to start and stop a small server with automator but my knoledge is very limited. I can't manage to set the path where the file is and I don't know how to stop the server.

So far I have this:

on run

set r to display dialog "Start or stop the NINJAM server ?" buttons {"Stop", "Start"}

if button returned of r is "Start" then

    #tell application "Terminal"
    #   activate

    do shell script "cd \"/Applications/ MUSIC/ Utilities/Audio IP/NINJAM/NINJAM/NinjamOSXServer ./ninjamsrv Server.cfg\""

    #end tell
else

    do shell script "Stop"

end if

end run

Any help is really apprectated. Thanks in advance.

Was it helpful?

Solution

NOTE that I'm using my own path here -- I put the ninjam server folder in the top level of my Applications folder. I had to create a 'term' file, which is a text file with this in it:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>WindowSettings</key>
    <array>
        <dict>
            <key>ExecutionString</key>
            <string>cd /Applications/NinjamOSXServer/;./ninjamsrv config.cfg</string>
        </dict>
    </array>
</dict>
</plist>

I saved this as LaunchNinjamSrvr.term and put it in the same folder as the ninjamsrvr. Then the script to use is:

set r to display dialog "Start or stop the NINJAM server ?" buttons {"Stop", "Start"}

if button returned of r is "Start" then
    do shell script "open /Applications/NinjamOSXServer/LaunchNinjamSrvr.term"
else
    do shell script "killall -INT -v ninjamsrv"
end if

[Occurs to me that I should give some explanation. Directly using the full path with the " config.cfg" parameter makes 'do shell script' choke. Splitting into two commands (but still using do shell script), like you see in the .term file, works to launch ninjamsrv, but makes the script editor (I use Smile) freeze. So that is (presumably -- I didn't want to test it by other means [script app, etc.]) a problem, and why I resorted to using the .term file. It used to be that you could, from the File menu in Terminal (as I recall), save a .term file directly, but that seems to have fallen by the way-side. So, at this point, I have a template that I use and just paste commands into the appropriate line. (But see http://discussions.apple.com/thread/3139585?start=0&tstart=0 -- wherein the technique of exporting Terminal Preference file is explained). I'm being a bit lazy in that the new form is .terminal, not .term ... anyway ... So now all that is left is doing the actual AS script. 'open' is a basic command line command which is just like opening or double-clicking in the Finder. If, for some reason your file opens in the wrong app or doesn't open, you might need to map it to Terminal.app (in the get info window) and/or change the extension to the more up--to-date '.terminal'. killall is like kill, designed to kill processes in various ways. I chose -INT because this is essentially like doing a control-c to interrupt the process.]

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top