Here's the gist of my little program
One python script that checks if there is a new file (movie file) in a certain directory and update an sqlite3 database accordingly, thus queuing files to be processed. Running every minute with launchctl.
Another python script that does the actual processing of converting the files with HandBrake command line interface. Also running every minute with launchctl.
In that second script, once the conversion is done, I want to start an applescript that will import the file into iTunes with certain metadata.
So, new movie file in directory -> file gets queued -> file gets converted -> file gets imported in iTunes.
The problem I have is with the applescript part. If I run my second python script (the one that converts then import) through the terminal, everything runs smoothly. The file gets converted and then the applescript imports it into iTunes. But if it's launchctl that is launching the script, it seems it's skipping the applescript part.
Here's the bit with the applescript in python
import subprocess, shlex
cmd = "/usr/bin/osascript /Users/alexis/Developer/Media/import_iTunes.scpt '{0}' ".format(file)
subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE)
And the applescript (I've removed some part for simplicity)
on run argv
set newTrackPath to posix file (item 1 of argv)
tell application "iTunes"
activate
set newTrack to add newTrackPath
end tell
end run
I've tried using subprocess.call(cmd), os.system(cmd) and subprocess.Popen(cmd).
The problem seems to be that you can't start osascript from python when that very python script is launched with launchctl.
Anyone has an explanation or a work around?
Thank you