Save name or picture captured on a file txt

Asked by Raphael Silva

I have one doubt, how do i do for save a "type(Key.PRINTSCREEN)" on a file txt? or the name print the picture on a file txt.

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Raphael Silva
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

after type(Key.PRINTSCREEN)
the screenshot is on the clipboard, which you cannot access easily from Sikuli (if it contains grafical content). You would have to simulate a workflow the same way, you would do manually (open some app, where you could add the image using CTRL-V and then save the file where you want).

But if you intention is to make screenshots and save them for later:

import os
import shutil
dir = "some path where you want to store the shots"
img = capture(SCREEN) # stores a shot as temp file
imgNew = "some unique image name"
shutil.move(img, os.path.join(dir, imgNew + ".png"))

Revision history for this message
Raphael Silva (raphaelcoel) said :
#2

Thank you.

could I too user this?

def printscreen():
    type(Key.PRINTSCREEN)
    openApp("mspaint")
    observe(1)
    type("v",KEY_CTRL)
    type(Key.F4, KEY_ALT)
    type(Key.ENTER)
    img = data(data)
    paste(test+"_"+img)
    type(Key.ENTER)

Revision history for this message
Raphael Silva (raphaelcoel) said :
#3

I tried use the your example, but gave error. Can you help me ?

# my script
import os
import shutil
dir = "C:\Documents and Settings\raphael.silva\Meus documentos\Minhas imagens\TEST"
img = capture(SCREEN) # stores a shot as temp file
imgNew = "test"
shutil.move(img, os.path.join(dir, imgNew + ".png"))

error:

[error] Mensagem de erro: Traceback (most recent call last):
 File "C:\DOCUME~1\RAPHAE~1.SIL\CONFIG~1\Temp\sikuli-tmp1929483483765301797.py", line 6, in
 shutil.move(img, os.path.join(dir, imgNew + ".png"))
 File "C:\Arquivos de programas\Sikuli X\sikuli-script.jar\Lib\shutil.py", line 205, in move
 File "C:\Arquivos de programas\Sikuli X\sikuli-script.jar\Lib\shutil.py", line 96, in copy2
 File "C:\Arquivos de programas\Sikuli X\sikuli-script.jar\Lib\shutil.py", line 52, in copyfile
IOError: (13, 'Permission denied', 'C:\\Documents and Settings\raphael.silva\\Meus documentos\\Minhas imagens\\TEST\\teste.png')

Revision history for this message
RaiMan (raimund-hocke) said :
#4

the folder

dir = "C:\Documents and Settings\raphael.silva\Meus documentos\Minhas imagens\TEST"

must exists before you can use it this way.

Revision history for this message
Raphael Silva (raphaelcoel) said :
#5

but it exists

Revision history for this message
Raphael Silva (raphaelcoel) said :
#6

OK, is working. Thank you RaiMain!

import os
import shutil
dir = "C:\mylib"
img = capture(SCREEN) # stores a shot as temp file
imgNew = "test"
shutil.move(img, os.path.join(dir, imgNew + ".png"))