Long running process defined as Service I created a service for starting a Virtual Box headless, which works fine - but the service does not end until the virtual machine is stopped again (the spinning wheel is in the menu bar (or whatever the bar in the top right is called).

This is understandable, as the command runs until the VM is closed again.

I tried appending "&amp;", using "nohup", "exec", but still, the "spinning wheel" does not disappear until the virtual box is closed again. 

I also tried to create an automator app, but the same.

Is there a way to either background the command, detach it, or make at least the spinning wheel to disappear?

EDIT:

Here is the plist:

?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
&lt;plist version="1.0"&gt;
&lt;dict&gt;
        &lt;key&gt;NSServices&lt;/key&gt;
        &lt;array&gt;
                &lt;dict&gt;
                        &lt;key&gt;NSMenuItem&lt;/key&gt;
                        &lt;dict&gt;
                                &lt;key&gt;default&lt;/key&gt;
                                &lt;string&gt;VBox Start Headless Ubuntu&lt;/string&gt;
                        &lt;/dict&gt;
                        &lt;key&gt;NSMessage&lt;/key&gt;
                        &lt;string&gt;runWorkflowAsService&lt;/string&gt;
                &lt;/dict&gt;
        &lt;/array&gt;
&lt;/dict&gt;
&lt;/plist&gt;


And a screenshot:
If you want to create a service on demand create a service with Automator and enter

/usr/bin/VBoxManage startvm "Ubuntu" headless &amp;


with the same settings as in your screenshot and that's it.

And here is a nice icon for the service to get rid of the default one:



Coipy and paste it in the info window.



If you want to start it at log-in create a shell script somewhere in your User folder and a plist in ~/Library/LaunchAgents:

Start Terminal and enter:

mkdir ~/bin
cd ~/bin
touch vboxmanage.ubuntu.sh
chmod 755 vboxmanage.ubuntu.sh


Use a text editor or nano to edit the script and add:

#! /bin/sh

/usr/bin/VBoxManage startvm "Ubuntu" headless


Then create a plist file in ~/Library/LaunchAgents with the name com.vboxmanage.ubuntu.plist and the content:

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
&lt;plist version="1.0"&gt;
&lt;dict&gt;
    &lt;key&gt;Label&lt;/key&gt;
    &lt;string&gt;com.vboxmanage.ubuntu.plist&lt;/string&gt;
    &lt;key&gt;ProgramArguments&lt;/key&gt;
    &lt;array&gt;
        &lt;string&gt;/Users/YourUserName/bin/vboxmanage.ubuntu.sh&lt;/string&gt;
    &lt;/array&gt;
    &lt;key&gt;RunAtLoad&lt;/key&gt;
    &lt;true/&gt;
    &lt;key&gt;LaunchOnlyOnce&lt;/key&gt;
    &lt;true/&gt;
&lt;/dict&gt;
&lt;/plist&gt;


Modify the file:

chmod 644 ~/Library/LaunchAgents/com.vboxmanage.ubuntu.plist


and launch it with:

launchctl load ~/Library/LaunchAgents/com.vboxmanage.ubuntu.plist


Afterwards the VM will be started after every log-in to your account