Have you ever found yourself trying to paste a value into a VirtualBox instance that’s not running an OS with clipboard integration?
If you know the keyboard scancodes of the characters you’d like to
input, you can use the controlvm
command of VBoxManage
as follows:
VBoxManage controlvm $VM_ID keyboardputscancode $DOWN_CODE $UP_CODE
Setting DOWN_CODE
to 10 and UP_CODE
to 90 inserts the letter ‘q’
That works, but even with some automation it’s a bit of a pain.
Here’s one way to do it under OS X without messing about with KeyCode generation and a running terminal.
In Automator, create a new Service.
The service should receive no input.
The first action should be “Get Clipboard Contents”
The second action should be “Run AppleScript” with the following code:
Save the workflow as ‘TypeClipboardContents’
Assuming the above steps worked for you, you can avoid having to use
the mouse by adding a keyboard shortcut for your service. I wanted to
use ⌘-V
as the shortcut, but only in VirtualBox.
/Applications/VirtualBox.app/Contents/Resources/VirtualBoxVM.app
⌘-V
⌘-V
If it worked, great. If not, retrace your steps and try again!
I revised the script on April 9th, 2016 to resolve an issue with
pasting of numbers and some
punctuation. This post on Stack Overflow
was helpful in understanding why my earlier version of the service
failed to insert characters which might have been found on the numeric
keypad. The newer version of the script handles these troublesome
characters with manually chosen key codes from
HIToolbox.framework/Versions/A/Headers/Events.h