I am trying to do two things at once: transcode a file/files and then move the files all together to another folder (where more applescripting then takes place). So everything has been working really well until I decided I needed a dialog box to display that the process was working, but only to have this dialog come up on the first file as it gets processed. Unfortunately, adding in this extra piece seems to have disabled my folder action that then moves the files once they are all in place. I don’t understand why this would happen.
Here is the code that transcodes the files, and I have set apart the area that is screwing things up in CAPS.
on open these_items
repeat with i from 1 to the count of these_items
--THIS IS THE PART THAT IS DISABLING MY FOLDER ACTIONS!
if i is 1 then
set ffmpeg_ok to "Transcoding has begun."
activate (display dialog (ffmpeg_ok) buttons {"OK"} default button 1)
end if
--END PART THAT IS DISABLING FOLDER ACTIONS
set this_item to (item i of these_items)
set the item_info to info for this_item
if folder of the item_info is true then
process_folder(this_item)
else if (alias of the item_info is false) and ¬
((the file type of the item_info is in the type_list) or ¬
the name extension of the item_info is in the extension_list) then
process_item(this_item)
end if
end repeat
end open
-- this sub-routine processes folders
on process_folder(this_folder)
set these_items to list folder this_folder without invisibles
repeat with i from 1 to the count of these_items
set this_item to alias ((this_folder as text) & (item i of these_items))
set the item_info to info for this_item
if folder of the item_info is true then
process_folder(this_item)
else if (alias of the item_info is false) and ¬
((the file type of the item_info is in the type_list) or ¬
the name extension of the item_info is in the extension_list) then
process_item(this_item)
end if
end repeat
end process_folder
-- this sub-routine processes files
on process_item(this_item)
set {name:Nm, name extension:Ex} to info for this_item
if Ex is missing value then set Ex to ""
if Ex is not "" then set Nm to text 1 thru ((count Nm) - (count Ex) - 1) of Nm
set destinationFile to quoted form of (POSIX path of (path to movies folder) & Nm & ".mp4")
with timeout of 10800 seconds -- three hour per movie time limit
do shell script "/Applications/ffmpegx.app/Contents/Resources/ffmpeg -i " & quoted form of POSIX path of this_item & " -vcodec mpeg4 -b 2000 -s 640x480 -acodec aac -ab 448 -ar 48000 -vol 1024 -f mp4 " & destinationFile & "&> ~/Library/Logs/ffmpeg_transcode/" & quoted form of Nm & ".log.txt & "
end timeout
--delay 45
end process_item
So just in case you need it, here is the folder action that is not occurring when I add in that i loop for my dialog box:
on adding folder items to this_folder after receiving added_items
checkStableSize(added_items)
delay 45
tell application "Finder"
set theFolder to path to movies folder from user domain
set targetFolder to folder "email@email.net" of home
move entire contents of theFolder to targetFolder
end tell
end adding folder items to
-- Handler to wait until a file is fully loaded.
on checkStableSize(theItem)
set F to quoted form of POSIX path of theItem
set sizeThen to first word of (do shell script "du -d 0 " & F) as integer --coercing to integer fixes the quote problem
repeat
try
delay 1 -- seconds (set to longer if needed)
set sizeNow to first word of (do shell script "du -d 0 " & F) as integer --coercing to integer fixes the quote problem
if sizeNow - sizeThen = 0 then exit repeat
set sizeThen to sizeNow
on error
exit repeat
end try
end repeat
end checkStableSize
I would greatly appreciate any suggestions you can throw my way as to what is going on. Thanks!