Hello,
I’m currently writing an AppleScript in order to make a folder action to convert a movie (so that it can be played by an iPod) and add it into iTunes.
Here is the text of my AppleScript:
on adding folder items to this_folder after receiving input_items
repeat with input_item in input_items
process_item(input_item)
end repeat
end adding folder items to
on process_item(this_item)
set myFileName to getFileName(this_item)
with timeout of 3600 seconds -- one hour per movie time limit
do shell script "/Applications/ffmpegx.app/Contents/Resources/ffmpeg -i " & the quoted form of POSIX path of this_item & " -f mp4 -y -maxrate 1000 -b 300 -qmin 3 -qmax 5 -bufsize 4096 -g 300 -vcodec mpeg4 -acodec aac " & the quoted form of ((POSIX path of (get path to temporary items folder from user domain)) & myFileName & ".mp4")
end timeout
do shell script "rm -f " & the quoted form of POSIX path of this_item
set newItem to (path to temporary items folder from user domain as string) & myFileName & ".mp4" as alias
tell application id "com.apple.iTunes"
activate
add newItem
end tell
do shell script "rm -f " & the quoted form of the POSIX path of newItem
end process_item
on getFileName(thefile)
set {oldDelims, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {":"}}
set mytextfilename to last text item of (thefile as text)
set AppleScript's text item delimiters to oldDelims
return mytextfilename
end getFileName
Don’t be afraid, I’m in the beginning of my project: the code is yet quite dirty (a lot of checkings are missing, …).
But let’s focus on my issue.
The thing is the script randomly stops after the “adding in iTunes” line of the code.
Sometimes the movie is added in iTunes and the script goes on, whereas sometimes the movie is added in iTunes and the script stops.
I tried to:
- catch an eventual error: there are none.
- delay 10 seconds after the adding (since the script should then remove a file used by the add-to-iTunes line): it didn’t help…
Do you have an idea of what’s happening?
I don’t expect you to correct my code: I can perform some tests on your advice.
Above all, I want to understand how the process can be so random (I work in a IT department, so I know how computers can be weird sometimes, but here… I’m very surprised!).
At the very end, if you have also some advice not related to that issue for my project, I would be very glad to hear from you.
Thanks in advance.
Model: MacBook
Browser: Safari 525.27.1
Operating System: Mac OS X (10.5)