utmapp / UTM

Virtual machines for iOS and macOS
https://getutm.app
Apache License 2.0
26.57k stars 1.33k forks source link

Paste text into VM through simulated typing #4503

Open NattyNarwhal opened 1 year ago

NattyNarwhal commented 1 year ago

In the event that clipboard sync into the guest isn't supported (i.e. installation, no guest tools support), it's annoying when you need paste text into the VM that's annoying to type out by hand (i.e. license keys, a medium-sized set of commands). It would be nice if UTM handled this.

I could imagine this works by just making the VM display accept paste:, then have it send the keys required as if the user typed them (with some debounce).

phirestalker commented 1 year ago

This would be great. Would the best way to be enable it automatically if clipboard sharing is disabled in settings? Possibly also if the spice client could not find a channel (i.e. the guest tools are not installed).

conath commented 1 year ago

You can already do this via the UTM URL Scheme. Any key press you want entered can be passed via the sendText command.

For example (from the above link): utm://sendText?name=Ubuntu%2020.04&text=abcdef types "abcdef" in the VM "Ubuntu 20.04"

phirestalker commented 1 year ago

OK, thanks. Now I just need to make a script. I assume I just need to urlencode the text to paste as it is usually a password.

conath commented 1 year ago

Yes, this is explained in detail in the wiki.

NattyNarwhal commented 1 year ago

It might be worth reopening, since this issue would be about exposing it in the GUI because the feature is already implemented on the backend.

NattyNarwhal commented 1 year ago

I haven't cloned or tried to build yet (it's late here and I don't know SwiftUI very well), but looking at the source:

osy commented 1 year ago

I think something like this in the toolbar would be cluttering. For some dumb apple api reasons we can’t actually use the menu bar for VMs without a significant front end rewrite and that would be the logical place for this option.

conath commented 1 year ago

Sorry, I did not realize the sendText isn't implemented for the new Virtualization backend.

NattyNarwhal commented 1 year ago

I think something like this in the toolbar would be cluttering. For some dumb apple api reasons we can’t actually use the menu bar for VMs without a significant front end rewrite and that would be the logical place for this option.

Hmm, I'm more familiar with raw AppKit, but couldn't the SwiftUI VM window or the SPICE view implement one of the selectors already in the menu (in this case, paste:), and have it work through the responder chain?

Having the other VM commands appear in the menu would be nice, but I'm not familiar enough with SwiftUI to know why.

steven-michaud commented 1 year ago

Another, simpler workaround which I now use regularly (on macOS guest VMs):

Turn on screen sharing in your VM. Then you can connect to it via Screen Sharing, from the host or any other Mac on your local network. Copy and paste works fine via screen sharing.

Note that I use Bridged Networking in my (virtualized) VMs. This may not work otherwise.

piejanssens commented 1 month ago

Sorry, I did not realize the sendText isn't implemented for the new Virtualization backend.

Any other way to get text copied from the host to the VM? (macOS-macOS and no option for screen share in my case)