Hi Tim Nevels,

I was trying to make the code work on my mac 10.6 / 10.8 but somehow I am not 
getting the snapshot on the desktop. (where I want them, for now)

I changed some of your code  (see below) but I am not sure if I understand if 
that makes it work.
I am not interested in a windows solution for now. 
I have no need for a "GetCurrentScreenNumber" so I removed that.
 the Screen Coordinates is fine
and the POSIX path name I modified (I think).

Then for quick results I put this code in a button object, so when clicked it 
would make a screen snapshot of the active 4D window and put it on the desktop. 
Unfortunately I don't get a snapshot. 

If you have some minutes to spare, can you give me some pointers where to look 
for the missing info to make this work. 

Thank you in advance for your time.

ernie hilgers (aruba)


> 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:=system folder("Desktop")+$fileName_t

>     // get screen coordinates
>   SCREEN COORDINATES($left;$top;$right;$bottom )
>   
> $screenRectOption_t:="-R"+String($left)+","+String($top)+","+String($right)+","+String($bottom)
> 
>     // get screenshot

$command_t:="screencapture "+$screenRectOption_t+" "+Convert path system to 
POSIX($filePath_t)


>   SET ENVIRONMENT VARIABLE("_4D_OPTION_HIDE_CONSOLE";"true")
>   LAUNCH EXTERNAL 
> PROCESS($command_t;$inputStream_t;$outputStream_t;$errorStream_t)
> 
>  // return file path
> $0:=$filePath_t
> 
> Tim

**********************************************************************
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
**********************************************************************

Reply via email to