Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Pimpampoum

macrumors newbie
Original poster
Jan 10, 2015
13
0
Hi there,

I will want to create an AppleScript to launch Homebrew's app.
The path of Homebrew's apps is "/usr/local/bin/".
For example, I would like to start with Mediatomb that is already installed.
I tried to create it, it works but I would like ameliorate it.

Here the code :
Code:
tell application "Terminal"
do script "/usr/local/bin/mediatomb"
end tell

I would like to close the first terminal that opens it (that allows to start Mediatomb) and optional launch Safari with Mediatomb web user interface (address IP and port).
Is this possible ? Any suggestions ?

Thanks !
 
Last edited:
Is this possible ? Any suggestions ?

Thanks !

You can try the do shell script and open location commands or look at the dictionaries of Standard Additions , Terminal and Safari. The URL property in the Safari dictionary might be useful. Depending on your IP and the port you set for Mediatomb it shouldn't be to difficult to do.

Info : https://developer.apple.com/library/mac/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_cmds.html#//apple_ref/doc/uid/TP40000983-CH216-SW40

Note : All of this can be done with a little shell script as well.
 
Last edited:
Thank you kryten2 for your answer, very interesting.
I have fixed the GUI port in the Mediatomb config file.
I added this in the code > tell application "Safari" to open location "http://x.x.x.x:pORT/" it works fine, it misses me the gimmick to close the first terminal, because I have not of ideas to do it actually.
 
Last edited:
Try :
Code:
do shell script "/usr/local/bin/mediatomb"

Just this single statement. Do not put this in a tell application Terminal block!
 
Not work with "do shell script" without of other statement.

When I launch the AppleScript with "do script" and tell, I have firstly the terminal that opens (TTY ttys000) and secondly the Mediatomb server that starts in a new Terminal windows (TTY ttys001).
The first is blank.
 
Last edited:
I've been trying to steer you away of using the Terminal application so you don't have to worry about opening or closing windows. You can get what you want by using these two statements :

Code:
do shell script "/usr/local/bin/mediatomb"
open location "http://x.x.x.x:PORT/"

If you persist on using the Terminal application you can try something like this :

Code:
tell application "Terminal"
	do script "/usr/local/bin/mediatomb"
	close last window
end tell

open location "http://x.x.x.x:PORT/"
 
Code:
do shell script "/usr/local/bin/mediatomb"
open location "http://x.x.x.x:PORT/"
That, it runs but I do not control service.
In AppleScript I can not stop it, it runs in loop (I have to kill the process with the command kill PID in the terminal).

Code:
tell application "Terminal"
	do script "/usr/local/bin/mediatomb"
	close last window
end tell

open location "http://x.x.x.x:PORT/"
That, it runs but the statement "close last window" wants to close the window where Mediatomb server is running.
 
Code:
tell application "Terminal"
	do script "/usr/local/bin/mediatomb"
	close first window
end tell

It works just like that !
We can change the icon from AppleScript ? (to put Mediatomb icon by example).
 
...
Code:
do shell script "/usr/local/bin/mediatomb"
open location "http://x.x.x.x:PORT/"
...

The do shell script AppleScript command will wait for the shell commands to terminate. If the shell commands don't terminate, the AppleScript will wait forever.

Put the mediatomb command into the background, and the shell script will then terminate, and the AppleScript will proceed:
Code:
do shell script "/usr/local/bin/mediatomb &"

EDIT
I did some reading here:
http://mediatomb.cc/pages/documentation

There's a command-line option (--daemon) that tells mediatomb itself to run as a daemon. This should be preferable to having the shell put it in background. So the preferred AppleScript command would be:
Code:
do shell script "/usr/local/bin/mediatomb --daemon"

This is a guess based only on reading the documentation and guessing that the OP wants mediatomb to continue running rather than terminate.

There are other options that may be useful, such as --pidfile and --user
 
Last edited:
Thank you both !
My goal is to control Mediatomb such as a service, an app that I launch and I close it if I run it as a daemon it will occupy a place in the RAM memory.
I did not will use it often.
It is to difficult explain you what I want, I do not write English well and I am newbie but I want to understand what I'm doing, sorry.

If I use this "do shell script "/usr/local/bin/mediatomb --daemon"" what will happen ?
It is also easy to create a daemon with Homebrew's apps and OSX environnement ?
I will see the Mediatomb daemon into launchctl list command ?
 
Last edited:
It is to difficult explain you what I want, I do not write English well and I am newbie but I want to understand what I'm doing, sorry.
I understand the difficulties, but it's important that you explain what you want clearly. If we don't know what you want, or what we understand from your writings isn't what you want, then we can't make solutions.

If I use this "do shell script "/usr/local/bin/mediatomb --daemon"" what will happen ?

Read the documentation for MediaTomb. If that doesn't explain things well enough, then try it and see what happens.

I don't know what will happen; I can only guess based on what I read.
I don't have MediaTomb, and I'm not going to install it just to run tests.

It is also easy to create a daemon with Homebrew's apps and OSX environnement ?
Homebrew is not just daemons.

If a particular Homebrew app is suitable for running as a daemon, then it's usually straightforward to run it as one. The preferred way to do that is by making a per-user LaunchAgent which can then be controlled with the 'launchctl' command-line tool.

If no one has made the launchd plist and posted it somewhere, then you will be the first. That means you'll have to try things and see what happens (experiment).

You should also be prepared for experiments to fail. That may mean losing data, so if you don't have a backup strategy, or aren't taking precautions, the worst will eventually happen and you'll lose data.

You seem to know what 'launchctl' is, but you haven't said anything about how well you understand its operation. It's a powerful tool, but incorrect use can create crashes or security holes. It's not something I recommend for someone who calls himself a "newbie".

If you're going to make LaunchAgents, you should read and understand the "Daemons and Services Programming Guide":
https://developer.apple.com/library...on.html#//apple_ref/doc/uid/10000172i-SW1-SW1

I will see the Mediatomb daemon into launchctl list command ?
No, because it wasn't launched by 'launchd'.
 
Thank you chown33.
When I execute the AppleScript "do shell script "/usr/local/bin/mediatomb --daemon"" MediaTomb runs such as a daemon without to open a Terminal window.
I can to see it with the command line "top" in the terminal after the launching.

So, how to do to stop the daemon by leaving the AppleScript ?
It is what I want.
It is necessary to add a stance in the script, but which.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.