Hi Guys,
Ok, I'm very new to AppleScript but I've been trying to automate the conversion of some AVI files to mp4/m4v files using folder actions on my mac.
I have attached the below script to a folder, when I copy one file into the tagged folder it works fine. When I copy lets say 3 or 4 files it will only process the first file copied in and never do anything with the others. I'm copying the files over the network so they take a while to all get into the folder.
If someone can maybe point in the direction to fix this, or fix my Script
on adding folder items to convertFolder after receiving filesToConvert
repeat with i from 1 to number of items in filesToConvert
set fileToConvert to item i of filesToConvert
set fileNameToConvert to POSIX path of fileToConvert
--display dialog fileNameToConvert
--display dialog POSIX path of fileToConvert
tell application "Finder"
set fileName to name of fileToConvert
set newFileName to text 1 thru ((offset of "." in fileName) - 1) of fileName & ".mp4"
end tell
do shell script "/Applications/HandBrakeCLI -i '" & fileNameToConvert & "' -o '/Users/bob/Desktop/AppleTV Files/" & newFileName & "' -f mp4 --loose-anamorphic -e x264 -q 20 -a 1 -E faac -6 auto -R 48 -B 160 -D 0.0 -x cabac=0:ref=2:me=umh:b-adapt=2:weightb=0:trellis=0:weightp=0 -v 1"
do shell script "mv '" & fileNameToConvert & "' '/Users/bob/Desktop/Movies to Write/'"
end repeat
end adding folder items to
Automate Avi to MP4/M4V
Forum rules
An Activity Log is required for support requests. Please read How-to get an activity log? for details on how and why this should be provided.
An Activity Log is required for support requests. Please read How-to get an activity log? for details on how and why this should be provided.
Re: Automate Avi to MP4/M4V
Your AppleScript looks okay to me, and the fact that your first file processes correctly makes me wonder if the delay in copying across the network is causing a folder action or AppleScript timeout on the subsequent files.
To check, try repackaging your script as a droplet, and drag'n'drop your files onto the droplet after they've finished coying across from network.
This is the format that works for me:
In Script Editor, save the script as an application (uncheck 'Run Only', Startup Screen' and 'Stay Open').
Cheers, Chris
To check, try repackaging your script as a droplet, and drag'n'drop your files onto the droplet after they've finished coying across from network.
This is the format that works for me:
Code: Select all
on open filesToConvert
repeat with i from 1 to the count of filesToConvert
set fileToConvert to item i of filesToConvert
...
end repeat
end open
Cheers, Chris
Re: Automate Avi to MP4/M4V
Ok, Will have a look into that creating a droplet then.
What I have noticed is that if I copy for example 4 files over the network to my desktop, then just move them into the folder with the action attached it works fine. So from that I do agree with your assumption that it's getting a timeout.
My other option is to create a script that I can select a couple of files in Finder and then execute the script against the selection.
What I have noticed is that if I copy for example 4 files over the network to my desktop, then just move them into the folder with the action attached it works fine. So from that I do agree with your assumption that it's getting a timeout.
My other option is to create a script that I can select a couple of files in Finder and then execute the script against the selection.
Re: Automate Avi to MP4/M4V
Or have your current script check that the files have finished copying into your target folder before you send them to HB.
Cheers, Chris
Cheers, Chris