change the captured file name --- use shutil.move()

Asked by Tim Wong

--- possible solution ------------

img = Screen(0).capture(27,170,963,159) # now contains filename in temp folder

import shutil
shutil.move (img, "path-and-name.png") # moves img to destination

e.g. move it to your current .sikuli:

import os.path
shutil.move (img, os.path.join(getBundlePath(), "some-name.png")

--------------------------------------------------------

Hi all,

I'm new of Sikuli user, I would like to ask some question about screen capture from Sikuli.

1. Is it possible to custom naming for screen capture from Sikuli (e.g. I don't want the file name like this: "sikuli-scr-3162482795590467766.png", I want it to be like "Abc_123_abc.png")

2. Is it possible to custom the save path of screen capture from Sikuli, default it will be stored in Temp folder, I would like to stored in let's say C:/SikuliProjectScreem/...

Thank you for all reply

Question information

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

--1. with X-1.0rc2 you can choose the naming option in the preferences (a manual option is provided)

--2. no, the save path is not choosable, but ....
Before you capture any picture, you should save your script to the wanted location. From now on your captures will be stored in this .sikuli folder. Have a look at the docs: http://sikuli.org/docx/globals.html#importing-other-sikuli-scripts-reuse-code-and-images to get an impression about the options you have to reference/use your pictures/code in other .sikuli's afterwards.

Revision history for this message
Tim Wong (timwong) said :
#2

Thanks RaiMan,

Maybe I didn't state my problem clearly. Actually, I would like to know if I use "Screen(0).capture(27,170,963,159)" can I have a custom naming function and custom location to save the capture?

Thanks once again for the great help!

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

ok, understood.

This you have to script with python features:

img = Screen(0).capture(27,170,963,159) # now contains filename in temp folder

import shutil
move (img, "path-and-name.png") # moves img to destination

e.g. move it to your current .sikuli:

import os
move (img, join(getBundlePath(), "some-name.png")

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

sorry --- again ;-)

import os.path
move (img, os.path.join(getBundlePath(), "some-name.png")

Revision history for this message
Tim Wong (timwong) said :
#5

Thank you for your reply. Your solution had solved my problem.

BTW it should be shutil.move (img, os.path.join(getBundlePath(), "some-name.png").

Best regards

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

Thanks (too early in the morning) (or should I say: you passed the test ;-)

I put the solution to the top of this post.

Revision history for this message
Tim Wong (timwong) said :
#7

Thanks RaiMan, that solved my question.

Revision history for this message
Julio (julioliu) said :
#8

These infomation is useful for me too, thanks a lot!