PDA

View Full Version : Automator Workflow: Export, Compress, Upload, Email to client




jonnyelwyn
Mar 29, 2012, 04:30 AM
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!



Red Menace
Mar 29, 2012, 09:50 AM
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.

jonnyelwyn
Mar 30, 2012, 07:17 AM
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

kryten2
Mar 30, 2012, 02:22 PM
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 :

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.

jonnyelwyn
Apr 3, 2012, 09:58 AM
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

emittan
Apr 3, 2012, 03:03 PM
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!

jonnyelwyn
Apr 3, 2012, 04:04 PM
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.

kryten2
Apr 3, 2012, 04:26 PM
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.

jonnyelwyn
Apr 3, 2012, 04:52 PM
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?

kryten2
Apr 3, 2012, 05:53 PM
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.

jonnyelwyn
Apr 4, 2012, 07:00 AM
Here they are in order...

kryten2
Apr 4, 2012, 10:09 AM
What's the result of your Filter Finder Items action. Do you see a reference to your .mov-1 file like so :

jonnyelwyn
Apr 4, 2012, 11:39 AM
i don't have any such mention??

kryten2
Apr 4, 2012, 12:40 PM
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?

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.

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.

jonnyelwyn
Apr 4, 2012, 05:02 PM
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!

kryten2
Apr 4, 2012, 06:12 PM
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.

jonnyelwyn
Apr 5, 2012, 03:43 AM
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.

kryten2
Apr 5, 2012, 01:30 PM
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.

kryten2
Apr 5, 2012, 07:10 PM
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.

-- 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

jonnyelwyn
Apr 7, 2012, 03:04 AM
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!

jonnyelwyn
Apr 7, 2012, 04:18 AM
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!

kryten2
Apr 7, 2012, 10:29 AM
Nice to read it's all working now.

jonnyelwyn
Apr 12, 2012, 12:32 PM
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??

kryten2
Apr 12, 2012, 03:06 PM
What exactly is Applescript telling you? Try some error handling and post the error.

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 :

tell application "EditAssist" to launch

Does is run without the error?

jonnyelwyn
Apr 12, 2012, 05:12 PM
tried posting your code to get an error number etc but it didn't work.

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

kryten2
Apr 12, 2012, 08:50 PM
Ok, so the error is in the run applescript action just like it says. You used 2 run applescript actions. The first for dropbox and the second for the mailing. Now you need to find out in which one of those the error occurs. Hint:
you can also do error checking in those 2 run applescript actions. Start with the first one. Do the same for the second one.

on run {input, parameters}
try
set DBText to (the clipboard as text)
on error errMsg number errNum
display alert errMsg & space & errNum message ¨
"An error occured" as warning --giving up after 10
end try
try
set DBURL to "http://dl.dropbox.com/u/xxxxxxxxx/"
on error errMsg number errNum
display alert errMsg & space & errNum message ¨
"An error occured" as warning --giving up after 10
end try
try
set FName to text ((offset of "Public:" in DBText) + 7) thru -1 of DBText
on error errMsg number errNum
display alert errMsg & space & errNum message ¨
"An error occured" as warning --giving up after 10
end try
try
set input to DBURL & FName
on error errMsg number errNum
display alert errMsg & space & errNum message ¨
"An error occured" as warning --giving up after 10
end try
try
return input
on error errMsg number errNum
display alert errMsg & space & errNum message ¨
"An error occured" as warning --giving up after 10
end try
end run

Going to take a little break now. It's ten to four in the morning over here. I'll look into the log command to see if it's usable for debugging.

jonnyelwyn
Apr 13, 2012, 03:50 AM
hope you weren't up late just for me!

Right I ran your code in both the workflow itself and on its own and I get the same message.

The workflow (archive email etc) does work perfectly, its just getting it to work by being fired up from a script run at the end of the compressor droplet.

If you see the third attachment I added the {input, parameters} to the run line and that gave me the same error code.

This is the only bit that's not working for some reason, this tiny code to launch my edit assist app (which is just the part 2 workflow saved as an app)
Can i change the tell application line to tell it to launch the workflow, what would that be?

Thanks so much
Jonny

jonnyelwyn
Apr 13, 2012, 04:14 AM
according to

http://lists.apple.com/archives/applescript-users/2004/Jan/msg00116.html

this is the error code.

-1721 <expression> doesn't match the parameters <parameterNames> for <commandName>.

kryten2
Apr 13, 2012, 03:20 PM
Can i change the tell application line to tell it to launch the workflow, what would that be?

You can but before that could you try this as compressor droplet script(remember to save as application!) :

on open (theFiles)
repeat with thefile in theFiles
display dialog thefile
end repeat
tell application "EditAssist" to launch
end open

For the workflow :
Save your EditAssist Automator app as an Automator workflow (.workflow file)

-- change line below to where you saved your .workflow
set workflowpath to "Macintosh HD:Users:martin:Desktop:Example.workflow"
set qtdworkflowpath to quoted form of (Posix path of workflowpath)
set command to "/usr/bin/automator -v " & qtdworkflowpath
set output to do shell script command

Also put the above code between an on open (theFiles) handler. First run it without the handler. Good luck.

Try to run the worflow code from scripteditor as well you'll get some results in the result pane.
Can you post the code that's behind the AppleScript Error (null) first tumbnail.

jonnyelwyn
Apr 14, 2012, 06:14 AM
The second code worked fine, and previous codes have worked fine.

I think the real problem now is that Apple Compressor 3.5 is not executing the script when it finishes encoding. I'm trying to find out why this is the case.

As suggested here http://www.proactiveinteractive.com/software/compressor/index.php

I tried saving it as an app with the 'on open (theFiles)' handlers but it still isn't working. Every script i write works just fine 'outside' of the compressor section of this ordeal. but i can't seem to get it hold together!

Think this is a compressor specific problem (which is why i had tried to do this part with folder action code before)

kryten2
Apr 14, 2012, 05:16 PM
Unfortunately I can't test this in real life with an example. Compressor 2 on my Leopard install (ppc hardware) runs just fine but qmasterd process crashes within seconds and on my Tiger install it's the other way round.