how to put a virtual machine launcher icon in the dock?

Discussions related to using VirtualBox on Mac OS X hosts.

how to put a virtual machine launcher icon in the dock?

Postby shpokas » 13. Sep 2008, 22:52

how to make a two step process (first launch VBox, then run VM) into one (just click on VM icon in dock)?
in linux it can be done if you check process list, find running virtual machine process and then create a separate shortcut with that entire string. but how do I do something similar in OS X?
at least I am not the only one :?
http://forums.virtualbox.org/viewtopic.php?t=7923&highlight=dock
shpokas
 
Posts: 2
Joined: 13. Sep 2008, 22:41

Postby amagine » 14. Sep 2008, 16:38

... Well you could wrap a shell script up in a AppleScript application and plop it in your dock...

Code: Select all   Expand viewCollapse view
do shell script "vboxmanage startvm NAMEOFYOURVIRTUALMACHINE"
Last edited by amagine on 14. Sep 2008, 17:06, edited 1 time in total.
amagine
Volunteer
 
Posts: 177
Joined: 28. Jul 2008, 19:52

Re: how to put a virtual machine launcher icon in the dock?

Postby Max_Schreck » 14. Sep 2008, 17:04

shpokas wrote:how to make a two step process (first launch VBox, then run VM) into one (just click on VM icon in dock)?
in linux it can be done if you check process list, find running virtual machine process and then create a separate shortcut with that entire string. but how do I do something similar in OS X?
at least I am not the only one :?
http://forums.virtualbox.org/viewtopic.php?t=7923&highlight=dock


i did this.

after installing virtual box double click on Mac. HD, choose application, scroll down and find the virtualbox icon, click on it and drag on the Dock.

now you see the icon on the Dock and when you click on it it hops and starts.
Max_Schreck
 
Posts: 30
Joined: 14. Sep 2008, 02:56

Postby andyf » 14. Sep 2008, 17:39

And this will launch Virtual box. Then you have to select which VM you want to launch. This is not what were are asking. Anyone who uses a Mac knows you can put an alias of an app in the dock!

What we are asking is how to put an alias of each VM in the dock so we can easily launch whichever one we want. Parallels and VM Aware can do this without a problem.
andyf
 
Posts: 4
Joined: 30. Jul 2008, 16:04

Postby tkwm » 14. Sep 2008, 18:47

The way amagine described works. Open Applescript/Scripteditor. Write the above mentioned command and save it as a program. Throw it into the dock and voila, it works. Additional you can give the program an icon of your choice with apple-I and cut and paste.
tkwm
Volunteer
 
Posts: 147
Joined: 3. Mar 2008, 17:56

Postby Max_Schreck » 14. Sep 2008, 18:59

@anndyf

ok, sorry my bad. now i see what you mean.
Max_Schreck
 
Posts: 30
Joined: 14. Sep 2008, 02:56

Postby shpokas » 14. Sep 2008, 21:31

well, yeah, thank you, guys! listen & learn!
shpokas
 
Posts: 2
Joined: 13. Sep 2008, 22:41

Postby h1d » 15. Sep 2008, 15:34

Thanks for the idea, never occured to me to do it this way.

I've made a little improvement from that one liner :wink: (Although this is for headless mode.)

You just paste the lower code in "Applications -> Apple Script -> Script Editor" and save as Application as described above.

Now you can drag the script to the dock and run an OS in headless mode. After it runs, it gives you a dialog to either 'Hibernate (through VBox feature)', 'Shutdown (as in virtually pressing the power button [you need acpid daemon running for Linux for this to work]) and 'Destroy (which will kill the OS instance immediately)'.

You need to change the first line of the script to write in your VM instance name. (Written as 'Ubuntu Linux' for now.)

If you want to use this for multiple OS, you just need to change the VM instance name and save it as a different application and you might want to actually put the folder in the dock instead.

If you want to enable RDP remote management, then you need to edit the 'VB_RDP' value to a port number instead of "off".

And if you want to look niftier than the default icon, you can google image for '[your OS name] icon' (be sure to pick the one with proper transparency) and grab one and use something like img2icns to turn the file into an icon file then use that as the custom icon.

Looking pretty.

Image

Code: Select all   Expand viewCollapse view
set VB_GUEST to "Ubuntu Linux"
set VB_RDP to "off"

set VB_PATH to "/usr/bin/"

set VB_VM to quoted form of VB_GUEST
do shell script VB_PATH & "VBoxHeadless -s " & VB_VM & " -v " & VB_RDP & " >/dev/null 2>&1 &"

display dialog "VirtualBox " & VB_VM buttons {"Hibernate", "Shutdown", "Destroy"} default button 1
set VB_ACT to button returned of result

set VB_CONTROL to VB_PATH & "VBoxManage controlvm " & VB_VM

if VB_ACT is "Hibernate" then
   do shell script VB_CONTROL & " savestate"
else if VB_ACT is "Shutdown" then
   do shell script VB_CONTROL & " acpipowerbutton"
else if VB_ACT is "Destroy" then
   do shell script VB_CONTROL & " poweroff"
end if



:D
h1d
Volunteer
 
Posts: 170
Joined: 3. Jul 2008, 02:10

Postby amagine » 18. Sep 2008, 05:35

Good work h1d,

'Tis the beauty and power of VBox, very easily scriptable and accessible.

Back from a spell on the ocean, look forward to seeing everyones excellent ideas and proposals for extending and using VBox.
amagine
Volunteer
 
Posts: 177
Joined: 28. Jul 2008, 19:52

Postby bananasontoast » 27. Jan 2009, 07:09

I am not very familiar with Apple Script so I am unsure quite how to adapt this. I currently have a Virtual Machine called Internet Explorer 7, which is a Windows XP image that contains IE7. Can anyone tell me how I might make a direct link shortcut? Also, is there a way to default to "save state" when closing?
bananasontoast
 
Posts: 1
Joined: 27. Jan 2009, 07:05

Postby tkwm » 27. Jan 2009, 18:02

It is pretty simple.
First try the above mentioned line
Code: Select all   Expand viewCollapse view
do shell script "vboxmanage startvm NAMEOFYOURVIRTUALMACHINE"


for your needs this should be
Code: Select all   Expand viewCollapse view
do shell script "vboxmanage startvm Internet Explorer 7"


a little more sophisticated script would be
Code: Select all   Expand viewCollapse view
set VB_GUEST to "Internet Explorer 7"

set VB_PATH to "/usr/bin/"

set VB_VM to quoted form of VB_GUEST
do shell script VB_PATH & "VBoxManage startvm " & VB_VM


Copy the provided code, open the AppleScript Editor and paste it into the edit-window, save it as a program, and you can throw the resulting program to the dock.

Further you can obtain yourself an icon, copy it to the clipboard, select the saved script-program, press Apple-I and paste it over the existing icon.

The way the vm acts when closing, is determined by the last used way, that means if you have saved the vm, next time it defaults to "Save state".
But I guess you can change this in the corresponding xml-file that you can find under $HOME/Library/VirtualBox/Machines/(machinename).

Also you can default there to seamlessmode.
tkwm
Volunteer
 
Posts: 147
Joined: 3. Mar 2008, 17:56

Re: how to put a virtual machine launcher icon in the dock?

Postby Eponymous » 29. Sep 2009, 06:53

I made a few changes to the longer applescript posted above by h1d, mainly to check whether the process was already running, and to handle the GUI app VirtualBox, giving the user the option to kill that as well. I also changed the command for starting the VM, but it's easy enough to change that to do what you want it to.

Code: Select all   Expand viewCollapse view
global VM
set VB_GUEST to "Name of your machine goes here"
set VB_VM to quoted form of VB_GUEST

set GUI to false

tell application "System Events"
   if exists process "VirtualBoxVM" then
      set VM to true
      if exists process "VirtualBox" then set GUI to true
   else
      set VM to false
   end if
end tell

if not VM then
   do shell script "VBoxManage startvm " & VB_VM & " >/dev/null 2>&1 &"
else
   
   display dialog "Are you sure?" buttons {"Cancel", "Yes"} default button 2
   set ans to button returned of result
   if ans = "Cancel" then return
   
   display dialog "VirtualBox " & VB_VM buttons {"Destroy", "Shutdown", "Hibernate"} default button 3
   set VB_ACT to button returned of result
   if GUI then
      display dialog "Shut down the GUI too?" buttons {"No", "Yes"} default button 2
      set ans to button returned of result
      if ans = "Yes" then
         tell application "VirtualBox"
            ignoring application responses
               quit
            end ignoring
         end tell
      end if
   end if
   
   set VB_CONTROL to "VBoxManage controlvm " & VB_VM
   
   if VB_ACT is "Hibernate" then
      do shell script VB_CONTROL & " savestate"
   else if VB_ACT is "Shutdown" then
      do shell script VB_CONTROL & " acpipowerbutton"
   else if VB_ACT is "Destroy" then
      do shell script VB_CONTROL & " poweroff"
   end if
end if
Eponymous
 
Posts: 2
Joined: 29. Sep 2009, 06:47
Primary OS: Mac OS X Leopard
VBox Version: OSE other
Guest OSses: Windows XP

Re: how to put a virtual machine launcher icon in the dock?

Postby bendog » 16. Nov 2010, 09:55

finally found this after much searching...
many thanks to all the people above!
bendog
 
Posts: 3
Joined: 16. Nov 2010, 09:27
Primary OS: Mac OS X Leopard
VBox Version: OSE other
Guest OSses: Ubuntu

Re: how to put a virtual machine launcher icon in the dock?

Postby Continuum » 24. Jan 2011, 19:17

Is there a way for the script application to hold the actual virtual machine and not just open the virtual machine? I want it to act more like an application so that the script holds the virtual machine so there are no other icons.
Continuum
 
Posts: 1
Joined: 24. Jan 2011, 19:10
Primary OS: Mac OS X other
VBox Version: OSE other
Guest OSses: Windows XP, Windows 7

Re: how to put a virtual machine launcher icon in the dock?

Postby bcassid » 16. Sep 2021, 19:46

Here's my method:

In your home folder, open the VirtualBox VMs folder

Open the folder of the VM you want to add to the dock

Highlight the .vbox file and choose File > Get Info or cmd-i

In the Get Info window, choose vmstarter.app if it's not already chosen

You can click the Change All button if you want this to work for all of your VMs

Now drag the .vbox file into the right side of the dock, to the right of the vertical line

When you click on it, it will open your VM without starting the app

Hope that helps,
Bob
bcassid
 
Posts: 17
Joined: 29. Sep 2017, 02:35


Return to VirtualBox on Mac OS X Hosts

Who is online

Users browsing this forum: No registered users and 26 guests