I’ve been working on a feature that I include in my 4D applications that allows the user to easily send me an email with a bug report.
The way it works is there is a toolbar button called “Bug Report” that the user clicks. It grabs some pertinent environment information about what the are doing in the 4D application and then opens a email with this information addressed to me. They can then add some details and send it to me. This is easily accomplished with the OPEN WEB URL command using “mailto:”. I’ve always wanted to be able to automatically create a screenshot and include that in the email. But “mailto:” doesn’t allow including attachments. So in the past I include in the email body instructions to the user: "Include a screenshot by selecting the window, press Alt-PrtScr, click back on this email and press Ctrl-V to paste the image.” (Windows users, of course) I’ve finally gotten around to finishing this feature to make it work the way I’ve always wanted. And it works on both macOS and Windows. I won’t go into details here on how I implemented creating the email — AppleScript on macOS and VBA script on Windows — but I will share how I implemented automatically taking a screenshot. First, I wanted to capture the entire screen, not just the frontmost window to get as much context as possible. I also wanted to support multiple monitors. I’ve got 2 monitors and most of my clients now have multiple monitors. The preference was to capture the currently active screen. On macOS there is a built in command for doing this called “screencapture” that you can run with LEP. I have a method called “GetCurrentScreenNumber” that will return the screen number of the screen the frontmost window is located on. I can use that with SCREEN COORDINATES to grab just that screen. On Windows I was not able to find a built in command to do this. Much searching lead me to a freeware program called “NirCmd”. http://www.nirsoft.net/utils/nircmd.html This utility does a lot of things, but all I’m interested in is the “savescreenshotfull” command. I’m getting an image of all screens in case the user has moves the 4D MDI to a screen other than the main screen. Here is my ScreenshotToFile method. You might find it useful. // =========================================== // PROJECT METHOD: ScreenshotToFile // PARAMETERS: $0 = path to file containing screenshot // DESCRIPTION: Take a screenshot in PNG format of the screen where the frontmost // window is located and returns the path to the file containing it. // macOS support for multiple screens. On Windows you get all screens. // CREATED BY: Tim Nevels, Innovative Solutions ©2018 // DATE: 1/5/18 // LAST MODIFIED: // ============================================ C_TEXT($0;$filePath_t) C_TEXT($fileName_t;$screenRectOption_t;$command_t;$inputStream_t;$outputStream_t;$errorStream_t) C_LONGINT($left;$top;$right;$bottom) // create temporary file path $fileName_t:="Screenshot "+String(Current date;ISO date;Current time)+".png" $fileName_t:=Replace string($fileName_t;"/";"-") // replace slashes with dashes in file name $fileName_t:=Replace string($fileName_t;":";".") // replace colons with periods in file name $filePath_t:=Temporary folder+$fileName_t If (<>macOS_b) // get screen coordinates SCREEN COORDINATES($left;$top;$right;$bottom;GetCurrentScreenNumber ) $screenRectOption_t:="-R"+String($left)+","+String($top)+","+String($right)+","+String($bottom) // get screenshot $command_t:="screencapture "+$screenRectOption_t+" "+GetPOSIXfilePath ($filePath_t) SET ENVIRONMENT VARIABLE("_4D_OPTION_HIDE_CONSOLE";"true") LAUNCH EXTERNAL PROCESS($command_t;$inputStream_t;$outputStream_t;$errorStream_t) Else // Windows // get screenshot $command_t:=Get 4D folder(Current resources folder)+"nircmdc.exe savescreenshotfull "+Char(Double quote)+$filePath_t+Char(Double quote) SET ENVIRONMENT VARIABLE("_4D_OPTION_HIDE_CONSOLE";"true") LAUNCH EXTERNAL PROCESS($command_t;$inputStream_t;$outputStream_t;$errorStream_t) If ($errorStream_t#"") Msg ("Nircmdc.exe screen capture problem."+<>CR+$errorStream_t;"Error") End if End if // return file path $0:=$filePath_t Tim ***************************************** Tim Nevels Innovative Solutions 785-749-3444 timnev...@mac.com ***************************************** ********************************************************************** 4D Internet Users Group (4D iNUG) FAQ: http://lists.4d.com/faqnug.html Archive: http://lists.4d.com/archives.html Options: http://lists.4d.com/mailman/options/4d_tech Unsub: mailto:4d_tech-unsubscr...@lists.4d.com **********************************************************************