Saving documents made in external programs to specific paths using finder?

Asked by Justin Snavely

Very beginning Python student who is using Sikuli to automate Video editing in Final Cut Pro on Mac (SL 10.6.7). I record psychiatric sessions of patients, and give them a copy of the video so I can get their release to use it for training. I typically create a final cut project for each client, add a quick title, import my video paths into the project, and dump those videos onto a timeline and export the timeline as a video into the source folder that the original videos came from.

So far, I have successfully started final Cut Pro, created a project, created a title and added it to the timeline, and saved the project to the desktop using an assigned variable from the start of the script. I am relying on keyboard shortcuts in FCP to do this, as FCP has no applescript or Automator functionality.

However, I'm stuck after that. If I try to import video into the project, how do I tell Finder where to go? The File paths to the raw videos is different for each client, and I am only aware of screen caps or using Tab and arrow keys to help Sikuli navigate through finder. However, that would require me redoing the script for each patient. I know I can do better.

I would like to be able to just create a small configuration text file with 1) the patient name, 2)the title for the video, 3)the file paths to the video resources, 4)the destination for the FCP project to be saved, 5)as well as the destination for the final exported video.

So, my questions are:
1) should I only use Sikuli for this?
2) How do I instruct Sikuli to navigate the finder window?
3) What is the best way for me to import my variables into my Sikuli project? Is that done with a .csv file? XML? add python based "input" dialogues and set each one to a variable? Or something less elegant?

Any help (or just tell me the names of the areas that I need to read about) in order to accomplish this would be ever so appreciated.

This is my script as is:
client = "Henry3";
Title = client + "\n Demo with therapist \nLocation, State\nMonth Year"
#def initFCP(client, Title); Not using this currently.
 switchApp ("Final Cut Pro.app");
#Unused currently, but I will create a if/else command to see if final cut is open already
# openApp ("Final Cut Pro.app");
# wait (15);
 type("4", KEY_CMD); #Special command)
 type("w", KEY_CTRL); #Close any other open project
 type("n", KEY_CMD+KEY_SHIFT); #New Project
 wait(1);
 type("s", KEY_CMD+KEY_SHIFT); #"Save As"
 wait( );#"Save window" image
 type(client + Key.ENTER);
 type("x", KEY_CTRL); #brings up title editor
 type("]",KEY_SHIFT+KEY_CMD);#FCP command to get to input field
 type(Key.TAB);#drops cursor into edit field"
 type(Title);
 type(Key.TAB);
 type(Key.F9);#adds title to timeline
 type("s", KEY_CMD)
 type("e", KEY_SHIFT+KEY_CMD) #export video

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
Best RaiMan (raimund-hocke) said :
#1

-- 1) should I only use Sikuli for this?
clearly YES.
Everything you need can be done since we can do everything, that is possible with standard Python 2.5. Any available Python module, that is either written in plain Python 2.5 or available as a Jython ported version can be installed and used.

-- 2) How do I instruct Sikuli to navigate the finder window?
This is the easiest way (manually): In a standard Mac open dialog (that should come up with import), you can type /, which opens the "goto folder" dropdown, and then type the complete absolute path to your folder containing the import and hit enter. Then enter the complete file name including extension into the search field (top right) and hit enter. Click into the window part containing the file name and type Key.DOWN (which selects it) and hit enter (can be done with some tabs too ;-)

I cannot test it, since I cannot type("/") on my german keyboard. So if you have a standard US installation, you might succeed in simulating this sequence.

Another hack you might try, if type("/") does not work:
put your working directory into the finders left sidebar under places. It should have a name starting with a character/number, that is unique among all entries in the sidebar including the section headers. so in the open dialog you can tab to the side bar and type("x"), which should select your folder if it starts with an x.

--- 3) config file per patient
The first option is to use csv-files, since this is directly supported by the Jython that comes with Sikuli.
A good starting point: http://www.doughellmann.com/PyMOTW/csv/

To make this easy to handle, you should hold your patients data in a dictionary:
- since a dictionary can easily be loaded from the csv-file
- and using a dictionary key is more readable than an array
 (p["client"] versus p[0])

p = {} # parameter set for a patient
p["client"] = "Henry3"
p["therapist"] = "someone"
p["location"] = "somewhere, somestate"
p["date"] = "month year"

# setup the title
templTitle = "%s\n Demo with %s \n%s\n%s"
p["title"] = templTitle % (p["client"], p["therapist"], p["location"], p["date"])

and similar for all the other data.

since a dictionary can easily be loaded from the csv-file.

Another option to use is YAML (which is more readable than a csv-file), but for Python/Jython, YAML-load is an external module, that you can get free from the web and you have to make it available to Sikuli Jython.

--- One more thing:
a trailing ; is not needed with Python. It is only necessary, if another statement is on the same line.

Revision history for this message
Justin Snavely (snagglebits) said :
#2

"\" works like a charm. And these are great resources and ideas, thank you so much. I will test stuff out and repost what I find. I am very excited!

Revision history for this message
Justin Snavely (snagglebits) said :
#3

Thanks RaiMan, that solved my question.