Automator Workflow: Export, Compress, Upload, Email to client

Discussion in 'Mac Programming' started by jonnyelwyn, Mar 29, 2012.

  1. macrumors newbie

    Joined:
    Mar 29, 2012
    #1
    Hello everyone,

    I've been trying to create a system that will export from Final Cut Pro, compress and upload via dropbox to a client in this way >>

    1. export from fcp to a watched folder
    2. once the file fully exports (file size stops growing) trigger a folder action to start compressor droplet
    3. Compressor droplet exports to another watched folder (which waits for full file size) before copying the file into a dropbox public folder, an applescript copies the dropbox public link, launches chrome and emails the link to a chosen address.


    Now it all works 'except' for the part of the scripting which makes sure that the file has been fully exported/compressed or copied (in all 3 different occurrences - file created from FCP, file created from compressor, copied to dropbox folder)

    Here is the code I am using for the 'waiting for file size to stop' script to make sure that each stage completes before moving on to the next...This is as it appears in the 'run applescript' window in the automator workflows... (i don't want to 'pause' them with seconds as any given export/compression will be different sizes and therefore take different amounts of time)
    ------------------
    on run {input, parameters}


    on adding folder items to thisFolder after receiving theItems
    repeat with f in theItems
    -- wait for the item to be all there. Since it can take a few minutes for a file to copy over.
    set Was to 0
    set isNow to 1
    repeat while isNow ≠ Was
    set Was to size of (info for f)
    delay 30 -- longer if getting the item is slow
    set isNow to size of (info for f)
    end repeat -- get next item f in thisFolder
    end adding folder items to

    return input
    end run

    ------------------------------
    BUT when i run the code by itself - automator says it isn't written correctly...(and it isn't working)

    Also is there a problem in the way compressor exports (creates a dummy file appended -1 which is 4k big and is then removed and replaced with a fully exported file when compressing is complete)
    The problem is that my 'copy to dropbox' and copy link is happening too soon and so it copies the dummy file.

    It all works separately (eg the code to copy the dropbox link and paste it into an email) but its just getting the applescript code to work that makes the process wait for the file to be either copied (so checking the file size until it stops growing) or is more than 4kb but then jumps to the final size for when it compresses. I just need to get the automator workflow to wait for the unique file specific length of time to then proceed to the next action...

    any help you can give would be gratefully received!
     
  2. macrumors 6502

    Joined:
    May 29, 2011
    Location:
    Littleton, Colorado, USA
    #2
    You can't have a handler inside another handler. You don't need a folder action handler though, since the Automator workflow would be passed the items, so just get rid of the adding folder items to declarations and use the script on the input items.
     
  3. thread starter macrumors newbie

    Joined:
    Mar 29, 2012
    #3
    Thanks for that, I think it fixed the script.

    My only problem now to solve is that when compressor creates the encoded version of the file it puts a dummy file in its place with extension mov-1 (and 4kb file size) and then replaces it with the final .mov once its finished creating it. (Full file size)

    I can't figure out how to get the workflow to wait for the file to be all there (as it stays at the same file size (4kb) for the length of time it takes to encode - so the script that i have won't work for that, right?

    I tried to have it so that it filtered the specified items by extension .mov and not being 4kb but it didn't seem to work. (although i've read on the net that the filter commands is buggy in Automator.

    I've attached a screen grab of the incorrect part of the workflow

    Any suggestions?

    many thanks
    jonny
     

    Attached Files:

  4. kryten2, Mar 30, 2012
    Last edited: Mar 30, 2012

    macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #4
    Use another run applescript action

    Your Get Specified Finder items results in a folder. If you want to Filter Finder Items,
    you should put a Get Folder Contents after the Get Specified Finder items.

    To see if understand it correctly :
    Your Edit Assist Encodes folder contains the dummy file with extension mov-1 (and 4kb file size)?
    When compressor is finished you get a final .mov file in the Edit Assist Encodes folder and the dummy file
    no longer exist?

    Could you try this please :
    Get Specified Finder items --> with Edit Assist Encodes
    Get Folder Contents
    Filter Finder Items --> filter for File extension is mov-1
    Run Applescript with this code :
    Code:
    on run {input, parameters}
    	(* Your script goes here *)
    	tell application "System Events"
    		set input to input as alias
    		get properties of input
    		set the_File_Size to physical size of input
    		try
    			repeat until the_File_Size is greater than 4096
    				set the_File_Size to physical size of input
    			end repeat
    		end try
    	end tell
    end run 
    The Run Applescript action will run as long as the mov-1 exists. I've tested this workflow with a 4kb .txt file
    and after removing the .txt file from command line in Terminal the Run Applescript action stops running.
    After the Run Applescript continue with :
    Get Specified Finder items --> with Edit Assist Encodes and ignore input
    Get Folder Contents
    Filter Finder Items --> filter for File extension is mov
    do your thing with de final .mov file
    Attached Thumbnail is in Dutch but shouldn't be a problem. Second action is the Get Folder Contents one.
     

    Attached Files:

  5. thread starter macrumors newbie

    Joined:
    Mar 29, 2012
    #5
    almost!

    I think the apple script you provided (and the tweaks to the workflow) is working as now it doesn't jump ahead to create the archive (which then goes into the dropbox public folder and copies the url link into a chrome gmail email.

    BUT its not doing any of that part at all now... (as in somehow the output from the apple script into the archive isn't happening??

    I've attached a screen grab where your script is at the top and then the transition of the workflow is underneath...

    I've probably done something wrong!

    (I did try filtering for .mov and having that before the 'create archive' but it didn't work either??)

    MANY MANY THANKS!
    I will be so happy when this finally works!
    cheers
    jonny
     

    Attached Files:

  6. macrumors newbie

    Joined:
    Feb 26, 2004
    Location:
    Lincoln Nebraska
    #6
    Why not compressor out of FCP?

    I'm not a programmer, but I'm a Final Cut Pro workflow specialist, and I can tell you that instead of exporting out of Final Cut and using a folder action to trigger another compression, you should simply add the output preset you prefer from Compressor to the list of items available in the "Share..." dialog in Final Cut Pro. That would leave you with one less step needed to script.

    To add the preset in FCP, choose File>Share... and in the dialog that appears, click the dropdown menu and choose "Other...". You'll now have full access to all of the settings you have built in Compressor, and on the right side is a check box for each one to put it "In Menu".

    Now instead of exporting, you can "Share..." it instead, and the video will come out of FCP in the format you desire.

    Hope that helps!
     
  7. thread starter macrumors newbie

    Joined:
    Mar 29, 2012
    #7
    thanks

    thanks for the suggestion. At the moment the export from FCP is going into a first folder which is triggered to launch a droplet when ever anything makes its way into the folder. This way I will always have the master file exported from FCP as well as the compression - which using the share menu, i wouldn't have as its just exporting the compressed version.

    but a good idea to remove a step in another workflow.
     
  8. macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #8
    Not giving up now, almost there

    The script doesn't return the input. Not necessary because that would be the
    mov-1 file. I also noticed that the script action and Get Specified Finder items
    are joined. Right click on the Get Specified Finder items action and choose ignore input.

    Questions : You want to create an archive from the final .mov file?
    When compressor is finished you get a final .mov file in the Edit Assist Encodes folder?

    Can you post your entire workflow as a few tumbnails but with the result of each action like the attached one as example? It would make things easier to debug. You could make something small so it won't take a lot of time for compressor to work on.
     

    Attached Files:

  9. thread starter macrumors newbie

    Joined:
    Mar 29, 2012
    #9
    thanks for your persistence

    I will upload screen grabs of the whole thing tomorrow as i've not got time tonight. Thanks for bearing with me!

    The script you kindly provided is giving up the error:

    ''Can’t make current application into type alias.''

    Any ideas?
     
  10. macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #10
    No problem

    Script requires a Finder item aka an alias as input. That's why it's below the
    Filter Finder Items action. It should only do one thing, to wait untill your .mov-1 file no longer exists and is replaced with the .mov file. I'm guessing you're using it below some other action. Will check again tomorrow.
     
  11. thread starter macrumors newbie

    Joined:
    Mar 29, 2012
    #11
    Screenshots for Debug

    Here they are in order...
     

    Attached Files:

  12. macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #12
    Run worklow to get results

    What's the result of your Filter Finder Items action. Do you see a reference to your .mov-1 file like so :
     

    Attached Files:

  13. thread starter macrumors newbie

    Joined:
    Mar 29, 2012
    #13
    no results - only this

    i don't have any such mention??
     

    Attached Files:

  14. macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #14
    Questions :

    Your Compressor droplet exports to another watched folder which is the Edit Assist Encodes folder?
    Was Compressor exporting when you ran your workflow? If so there should be that dummy mov-1 file you mentioned.
    If you filter for mov file do you get any result?
    Can you save your workflow and attach it as a zip file?

    Questions:

    1) export from fcp to a watched folder. Is this also the Edit Assist Encodes folder? What extension does this file have? Is there also some kind of dummy file?
    2) So were are talking about another wait here this time for FCP? What is the code for that folder action?
    3) See my first question at the top.
     
  15. thread starter macrumors newbie

    Joined:
    Mar 29, 2012
    #15
    workflow as zip

    So the full workflow is

    1. Export from FCP to Edit Assist Uploader Folder
    This creates a master file size version (BIG) of the film from Final Cut Pro
    2. The Uploader folder has a folder action to run a compressor droplet to create an email-able file. This all happens based on a totally separate workflow that is working fine.

    3. The Edit Assist Encodes folder also has a folder action set to run the workflow we've been trying to make work.
    4. This is supposed to wait for the compressor file (first a mov-1 dummy file then the real .mov file) to be all there and then when it is, make an archive in the public dropbox folder, collect the url and paste it into an email that is then sent out. (in this case via chrome)


    NOW.
    An interesting thing has happened when I ran the workflow (had it open and pressed run) while compressor was compressing so that i could do a debug screengrab. For the first time the whole thing did work (as in it made an archive and sent an email)

    BUT when i opened the archive it was still the .mov-1 verison (798k - must have grabbed it part way through??) and not the final compressed version of the file (2.8mb)

    I'm not sure why this happened as normally it doesn't work.

    Here are the screengrabs for the results info during the compression and after the compression. I've also attached the workflow as a zip.

    THANKS SO MUCH!
     

    Attached Files:

  16. kryten2, Apr 4, 2012
    Last edited: Apr 4, 2012

    macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #16
    Thank you for your patience

    I have a feeling we're very close to get it working. Could you run your workflow again if it's not to much work but this time with a Get Folder Contents and Filter Finder Items (for mov file) after the second Get Specified Finder Items. Post the result of the Filter Finder Items and Get Folder Contents as tumbnail but with the result shown like this : I mean clicking on the middle button just below result. You can disable all actions starting with Make archive and below to speed things up.
     

    Attached Files:

  17. thread starter macrumors newbie

    Joined:
    Mar 29, 2012
    #17
    Strange

    No work at all! I'm just thankful you're so happy to help! It is very much appreciated!

    Added those two elements, this time around it didn't work all the way through because it didn't find anything to make into the archive (?). Here are the screengrabs.
     

    Attached Files:

    • 1.png
      1.png
      File size:
      82.3 KB
      Views:
      52
    • 2.png
      2.png
      File size:
      73.9 KB
      Views:
      38
  18. macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #18
    Hang in there

    As you can see the result of the Get Folder Content is only the mov-1 file. Perhaps it takes some time for the mov-1 file to be replaced with the final mov file. Can you run something through compressor again but this time open a finder window showing the contents of your Edit Assist Encodes, no need to run the workflow. Normally you would see your mov-1 file (of that we can be certain) but the interesting part would be to see your mov-1 file change into the final mov file. Don't worry I've a few more tricks up my sleeve. If push comes to shove I'll install FCP. It's on a backup disk of mine, i'll have to search for it though. I think it's FCP 4. Can I make a compressor droplet with that version?

    When compressor is working could you open Terminal(you'll find it in your applications-->utilities folder) and paste this command into the Terminal window and press return : ps -xco command > psoutput.txt
    Do this again when you see the mov file in the finder window but this time change the command to this : ps -xco command >> psoutput.txt
    Post the psoutput.txt as attachement. The file is in your home folder.
     
  19. macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #19
    Very close to result.

    From the start of your post I was thinking there's got to be a way of scripting this. After all it was FCP an Apple product. As you were trying to use Automator I hadn't given it any more thought. But tonight I decided to dive in a little deeper and guess what. I found this on the net :

    Compressor is a file conversion utility included with Apple's Final Cut Pro. It's very handy. There's an option in the preset inspector to run an AppleScript upon completion ("Execute action on output").Just copy/paste this into Script Editor, save it as an application, and attach it to your Compressor preset using the Applescript checkbox mentioned above.

    Code:
    -- It will be up to you to test it but I think it would be best if your final mov file would be the only file that exists in the Edit Assist Encodes folder  
    -- I'm putting numerous comments in the script to clarify things a bit
    on open (thefiles)
    	--setting the_Encoded_Folder to /Users/jonny/Desktop/Edit Assist Encodes --> this is POSIX path notation
    	set the_Encoded_Folder to (path to desktop as text) & "Edit Assist Encodes"
    	-- setting the_Public_Folder to /Users/jonny/Public --> this is POSIX path notation
    	set the_Public_Folder to (path to public folder)
    	--There should only be one file, but just in case send it through a loop
    	-- I've disabled the loop. I think we don't need it. I could be wrong. We'll see when you run the script. 
    	(*
    	repeat with thefile in thefiles
    	end repeat
    *)
    	-- Next we make a zip file with a name of Edit Assist Encodes.zip of the Edit Assist Encodes folder in the Public folder. The workflow would do the same. The Get Specified Finder Items would result in the Edit Assist Encodes folder. The Create archive would result in an Edit Assist Encodes.zip file in your Public folder because same name as input in the save as box is used.
    	do shell script "ditto -c -k --keepParent " & quoted form of POSIX path of the_Encoded_Folder & " " & quoted form of POSIX path of the_Public_Folder & "Edit\\ Assist\\ Encodes.zip"
    	-- Next in the workflow the result of the Create archive would be copied to clipboard which would give this as result /Users/jonny/Public/Edit Assist Encodes.zip. We get the same by using the next line.
    	set the_Folder_Archive to (path to public folder as text) & "Edit Assist Encodes.zip" as alias
    	-- Next in the workflow was a bit of code related to dropbox but this line : set FName (offset of "Public:" in DBText + 7 thru -1 of DBText resulted in garbage. I'm guessing you were aiming for this kind of result : "http://dl.dropbox.com/u/xxxxxxxxx/Edit Assist Encodes.zip" If so we use this code below : BEWARE no file is uploaded here I think or it's something I'm missing. I don't use dropbox. The only thing done here is composing an URL.
    	set DBURL to "http://dl.dropbox.com/u/xxxxxxxxx/"
    	set the DBTextInfo to info for the_Folder_Archive
    	copy displayed name of DBTextInfo to FName
    	set input to DBURL & FName
    	return input
    	-- The result of return input would be "http://dl.dropbox.com/u/xxxxxxxxx/Edit Assist Encodes.zip" In the workflow it get's copied to the clipboard and passed on to the next bit of code of opening Chrome and composing a mail. But it's not used in the tell block. The return input result after the end tell would result in the same result as the one after set input to DBURL & FName namely "http://dl.dropbox.com/u/xxxxxxxxx/Edit Assist Encodes.zip". I admit this baffles me a bit.
    	tell application "System Events"
    		
    		tell application "Google Chrome" to activate
    		
    		open location "http://mail.google.com/mail/#compose"
    		
    		delay 5
    		
    		keystroke "youremail"
    		keystroke "@"
    		keystroke "gmail.com"
    		keystroke tab
    		delay 3
    		keystroke "A file from Jonny Elwyn"
    		keystroke tab
    		delay 3
    		keystroke "v" using command down
    		delay 3
    		keystroke tab
    		keystroke return
    		
    		
    	end tell
    	
    	return input
    end open
    
    on run
    	display dialog "This is meant to be called from Compressor."
    end run
    I've sent you a Private Message because I thought this was a breakthrough. I hope I was not too intrusive
     
  20. thread starter macrumors newbie

    Joined:
    Mar 29, 2012
    #20
    thanks for all your hard work

    Hey Kryten2

    Thanks for all your hard work - and not at all intrusive!

    First of all here is the psoutput text which i did during compression and after.
    (i couldn't really make heads or tail of it!)

    Secondly - thanks for the script! I shall test it out. I did know that you can add scripts to compressor outputs, but the thing is that I wanted to be able to export a master file from FCP and then have compressor kick in later.

    BUT because the first part of my workflow (A watch folder with a compressor droplet attached) is working, I guess there is no reason not to append an apple script on the end of the compressor droplet - thereby saving the hassle of the compression watcher not working.

    So onto your script.

    The bit that 'returned garbage' in the dropbox section is because the archive from Edit Assist Encodes is being copied into machd/users/dropbox/public/
    which is like a private ftp section and each file gets given a unique url to send to whoever you want to download it.
    In the code i posted on the net I had removed my unique dropbox number and replaced it with lots of XXXXX for privacy.

    In the workflow version the archive is created based on the exported filename from FCP which is carried over to the compressor output. But in your script it looks like every zip file would be called Edit Assist Encodes.zip

    Is there a way to keep it unique to the file name?

    I will try adding the second half of the automator workflow to the compressor droplet and see if that works from start to finish!
     

    Attached Files:

  21. thread starter macrumors newbie

    Joined:
    Mar 29, 2012
    #21
    Success!

    Well your thought about compressor inspired me to try the automator workflow another way.

    This is how it is now working....

    1. Export from FCP to watch folder
    - runs folder action to run compressor droplet (with new apple script ending)
    2. Compressor compresses file into Edit Assist encodes and runs the second half of the automator workflow (creating the archive, uploading to dropbox and emailing)

    success it works!
    Thanks so much for all your time, effort, patience and insight!

    I only wish you could make use of it!
    Many thanks again!
     
  22. macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #22
    Thank you for the feedback

    Nice to read it's all working now.
     
  23. thread starter macrumors newbie

    Joined:
    Mar 29, 2012
    #23
    broken?

    Ok I seem to have broken it.

    the weak link is this...

    The file lands in the first folder and triggers a droplet from compressor.
    The compressor droplet has an instruction to run an applescript once it has finished compressing.
    The script is this...
    on run
    tell application "EditAssist" to launch
    end run

    This runs the second part of the workflow (that archives and emails) which i've saved as an app called EditAssist.

    Now for some reason applescript keeps telling me that it won't work.
    (although the script works to launch any other app)

    Is it because i made the edit assist app myself, it can't find it??
     
  24. macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #24
    What kind off Applescript error?

    What exactly is Applescript telling you? Try some error handling and post the error.

    Code:
    on run
    	try
    		tell application "EditAssist" to launch
    	on error errMsg number errNum
    		display alert errMsg & space & errNum message ¬
    			"An error occured" as warning giving up after 10
    	end try
    end run
    If you run this in scripteditor :

    Code:
    tell application "EditAssist" to launch
    Does is run without the error?
     
  25. thread starter macrumors newbie

    Joined:
    Mar 29, 2012
    #25
    error message

    tried posting your code to get an error number etc but it didn't work.

    The error i get every time is this one...
     

    Attached Files:

Share This Page