นี่คือ hot topic (หัวข้อน่าสนใจ/ปัจจุบัน) คุณทำ various installations และ operations ภายใน VMs ใช้ VirtualBox และคุณอยาก take screenshots documenting activities ของคุณ ใน VMware range ของ virtualization products screenshot feature อยู่ใน system menu ดังนั้นมัน very simple thing to do (เรื่องง่ายมาก) ใน VirtualBox ไม่มี option นี้ available นี่หมายความว่าคุณต้อง resort to (ต้องใช้วิธี/พึ่งพา) taking screenshots ใช้ host utilities เช่น various screenshot programs, PrtScrn หรือ Alt+PrtScrn และ key combos อื่นๆ ไม่ได้ always simple (ไม่ได้ง่ายเสมอไป) แต่ biggest problem (ปัญหาใหญ่ที่สุด) คือ VirtualBox treats (จัดการ) a part of its interface เป็น guest OS screen space และ thus (ดังนั้น) screenshots ของคุณ never come out clean (ไม่มีอะไรสะอาด/ไม่มีขอบ)
All right (แล้ว) ทั้งหมดนี้บอกเราว่าปัญหาคืออะไร คุณอยาก able to (สามารถ) take screenshots ของ guest systems จาก outside (ภายนอก) โดยไม่ต้อง share folders และ copy & paste screenshots จากภายใน VMs ไป host คุณอยาก functionality บน host ที่จะ take screenshots excluding (ยกเว้น) inner VirtualBox border ที่ affects screenshots สามารถทำได้ไหม? คำตอบคือ yes (ได้) ตั้งแต่ version 4.0 ติดตามมา
Screenshots, today (ภาพหน้าจอ วันนี้)
ไม่ว่าคุณจะใช้ SnagIt, IrfanView, GIMP, Gnome Screenshot, KSnapshot หรือ software อื่นๆ results จะ always be the same (เหมือนกันเสมอ) คุณจะมี annoying (รำคาญ) top และ bottom border ที่บอกทุกคนว่าคุณเพิ่ง screenshot VirtualBox window ตัวอย่างเช่นแบบนี้:
นี่ annoying (รำคาญ) คุณ only want (ต้องการแค่) blue rectangle ดังนั้นคุณต้อง manually crop (ครอป/ตัด) area วิธีนี้ waste (เสีย) precious time (เวลาที่มีค่า) ตอนนี้มี simple alternative (ทางเลือกง่าย) แต่ต้องใช้ VirtualBox command line
Solution: ใช้ VBoxManage จาก commandline
New feature นี้ available ใน versions 4.0 และ above ดังนั้นจะไม่ work บน older editions สิ่งที่คุณต้องทำคือ invoke (เรียกใช้) คำสั่งต่อไปนี้:
VBoxManage controlvm <vm name> screenshotpng <filename>.png
That's the whole of magic (นั่นคือทั้งหมดของเวทมนตร์) โดย <vm name> คือชื่อ VM ของคุณ และ <filename> คือ string ใดๆที่คุณอยากใช้ identify screenshots ภายหลัง
และนี่คือ Ubuntu Lucid example:
Scripting (การเขียนสคริปต์)
คุณยังสามารถ partly automate (ทำให้อัตโนมัติบางส่วน) procedure นี้ได้ เพื่อให้คุณไม่ต้อง always manually go to command line และ invoke desired command ก่อนอื่น คุณสามารถ create scripts ที่ execute คำสั่งให้คุณ ผมจะ demonstrate ใช้ BASIC (BAT) บน Windows และ BASH บน Linux ที่สอง คุณสามารถใช้ generic identifiers สำหรับ images เพื่อไม่ต้อง manually input names ทุกครั้ง ใช้ environment variable RANDOM หรือ time stamp ดูเหมือน good options สุดท้าย คุณสามารถ create shortcuts ไม่ว่าจะบน desktop หรือ application panels และ add hotkey combos ที่ invoke shortcuts หรือ applications
Windows example (ตัวอย่าง Windows)
ใช้ command line ใน Windows อาจไม่ดู most natural thing (สิ่งที่เป็นธรรมชาติสุดๆ) แต่ quite easy (ค่อนข้างง่าย) Once you master the basics [sic] (เมื่อคุณ master basics แล้ว) คุณสามารถ move on to writing batch files
คุณสามารถ hardcode image names หรือใช้ something that will create unique strings each time ไม่ว่าจะ time หรือ date string หรือ random number จากนั้นเขียน simple batch file ที่ execute คำสั่งให้คุณ
echo off
<full path to VBoxManage.exe" controlvm <vm name> screenshotpng <filename>.png
More specifically (โดยเฉพาะเจาะจง) ใช้ example ที่มือ เรา Windows 8 guest เราสร้าง batch file สำหรับ VM ของเราที่จะ append random string ไปที่ image names เพื่อทำให้ unique เรา place images ใน Share directory แต่คุณสามารถใช้ anything you like VM name ก็สามารถ treat as hardcoded value หรือ input argument
echo off
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" controlvm Windows-8 screenshotpng C:\Share\image-%random%.png
สุดท้าย คุณสามารถ create shortcut วางที่ไหนสักที่ แล้ว edit properties และ add shortcut key combo ที่จะ invoke it นี่จะทำให้งานของคุณ easier และ faster มาก
Linux example (ตัวอย่าง Linux)
บน Linux มัน even easier (ง่ายกว่านั้น)
เราสามารถสร้าง simple script ที่มีแค่ one line นั้น
#!/bin/bash
VBoxManage controlvm <vm name> screenshotpng ~/image-`date +%s`.png
exit 0
End result จะเป็น images ใน home directory ของคุณ พร้อม elapsed seconds count since 1970 เป็น appended number ตอนนี้ คุณสามารถ hardcode VM name ใน script หรือ pass it to script as input argument แต่ this requires interaction (ต้องการการโต้ตอบ) when executing หรือคุณอาจ parse process table และพยายามหา name ของ current running VM container เพื่อทำ fully unattended script คุณยังสามารถใช้ which command เพื่อ detect full path ของ VBoxManage binary
จากนั้น คุณสามารถ create shortcuts ตัวอย่าง ใน Gnome add custom launcher ไปที่ top panel และใน command field เขียน full path ไปที่ screenshot script ของคุณ และคุณจะมี automated solution ที่ almost equivalent to (เกือบเทียบเท่า) executing a menu option และ possibly even faster (อาจเร็วกว่า) There are many options แต่นี้ควร get you started (ช่วยเริ่มต้นได้)
Another advantage (ข้อได้เปรียบอีกอย่าง)
Method นี้มี another bonus ที่ external utilities ไม่มี มันจะ grab (จับ/ดึง) contents ของ entire screen (หน้าจอทั้งหมด) ของ guest ของคุณ แม้จะ only partially shown (แสดงเพียงบางส่วน) บน host monitor ของคุณ ดังนั้นหากคุณใช้ different resolutions สำหรับ host และ guest, multiple monitors หรือ run machines windowed คุณ won't get any annoying cropping (จะไม่ได้ annoying cropping) ตัวอย่าง โปรดสังเกต Windows 8 VM นี้ ดู horizontal และ vertical scroll bars? นี่หมายถึงคุณ not seeing all there is to see (ไม่ได้เห็นทั้งหมดที่มี) แต่ screenshot capture feature solves that problem (แก้ปัญหานั้น)
สรุป
There you go (นั่นคือแล้ว) คุณเพิ่งเรียนรู้ how to get around (วิธีหลีกเลี่ยง/แก้ไข) that one most annoying thing ใน VirtualBox managing VM screenshots ด้วย some use of command line คุณจะสามารถ almost 100% automate screenshot taking ของคุณ
Tutorial นี้ focus บน VirtualBox และ screenshots แต่ยังสอนนิดหน่อยเกี่ยวกับ how to think laterally (คิดแบบข้างเคียง/กว้าง) exposes (เปิดเผย) VirtualBox powerful command line management how to use scripts, shortcuts และ shortcut combo keys เพื่อทำให้ชีวิตง่ายขึ้น รวมถึง Windows และ Linux flavors บาง BASIC บาง BASH works just fine (ทำงานได้ดีเพียงพอ) Well ผมหวังว่าคุณชอบ have fun (สนุกกันเถอะ)
ขอแสดงความนับถือ