Question

I am looking to have the ability of importing a capture of my screen into my LiveCode application.

I generally use the following key combination on my mac: cmd + shift + 4

then imported the image as a control or referenced the image within an image control.

set the fileName of image 1 to "/path/to/image.png"

Is there a way to do this directly by script, bypassing the need for these additional steps?

Was it helpful?

Solution

on mouseUp
  import snapshot
end mouseUp

note that you can also be much more specific with the import command, for example specifying the whole screen, or just one part or object of a stack. Make sure to check out all possibilities of the import snapshot command in the dictionary.

on mouseUp
  import snapshot from line 1 of the screenrects
  import snapshot from me
end mouseUp

OTHER TIPS

You should be able to use the "import snapshot" command for this purpose. The following script allows you to take a snapshot of the whole screen-

import snapshot from rect (the screenrect)

or if you wish to have the same functionality as cmd + shift-4 then it would simply be:

import snapshot

This will bring up a small arrow that you drag to capture a specific area of the screen.

Importing snapshot creates a new image object on your stack that will be, by default named a variation of "image id 100*"

A list of ways to capture a snapshot using the "import snapshot" command can be found below. These are taken form the "import snapshot" dictionary entry-

To import a snapshot for a portion of a stack you use the form: import snapshot from rect[angle] of window windowID Where windowID is the windowID property of the required stack.

To import a snapshot of a specific (non-stack) object, use the form: import snapshot from rect[angle] of chunk Where chunk is any chunk expression resolving to a control, or any expression evaluating to a control reference.

To import a snapshot of an object that has graphic effects applied to it, use the with effects form: import snapshot from rect[angle] of chunk with effects Where chunk is any chunk expression resolving to a control, or any expression evaluating to a control reference.

To import a snapshot of an object in iOS use the form: import snapshot from [ rectangle rect of ] object

To import a snapshot of the screen in iOS use the form: import snapshot from rectangle rect

**You could try this in Python & Linux**

import gtk.gdk

w = gtk.gdk.get_default_root_window()
sz = w.get_size()
print "The size of the window is %d x %d" % sz
pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,False,8,sz[0],sz[1])
pb = pb.get_from_drawable(w,w.get_colormap(),0,0,0,0,sz[0],sz[1])
if (pb != None):
    pb.save("screenshot.png","png")
    print "Screenshot saved to screenshot.png."
else:
    print "Unable to get the screenshot."
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top