[Automator] - Multiple Workflows Within Folder Action?

Discussion in 'Mac Programming' started by Nor*Cal, Oct 29, 2014.

  1. Nor*Cal macrumors regular

    Joined:
    Jun 17, 2007
    Location:
    Irvine, CA
    #1
    So I have a folder action which looks like the following:

    [​IMG]

    It begins when a file is dropped into test folder, and ends when the file is moved to test folder 2.

    However, I have another set of actions that I would like to run after the file is moved. It seems that after the last step, it is impossible to have another set of actions to occur in the original test folder. As a result I have had to create another folder action (on the same test folder) with a delay of 30 seconds or so (to allow the first folder action to complete). Is there action that I can put after the folder move to "start fresh" and allow for a new set of actions?
     
  2. kryten2, Oct 30, 2014
    Last edited: Oct 30, 2014

    kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #2
    Describe exactly the workflow/actions you want to do when a file is dropped into test folder and the other set of actions you would like to run after the file is moved. There's no need for the Get Folder Contents and Get Selected Finder Items actions in a Folder Action. You can also create AppleScript-based folder actions.
     
  3. Nor*Cal thread starter macrumors regular

    Joined:
    Jun 17, 2007
    Location:
    Irvine, CA
    #3
    Thanks for the reply, this is what is happening in detail...

    Action 1 (Runs on receiving file in folder 1)

    1. Get Folder Contents
    2. Get Selected Finder Items
    3. Filter Finder Items (kind is movie)
    4. Get Selected Finder Items
    5. Move Finder Items (to Folder 2)

    Action 2 (Runs on receiving file in folder 1, currently has a pause as to not overlap with action 1)

    1. Pause (for 10 seconds)
    2. Filter Finder Items (find empty folders)
    3. Get Selected Items
    4. Move Items to Trash
     
  4. Red Menace macrumors 6502

    Joined:
    May 29, 2011
    Location:
    Littleton, Colorado, USA
    #4
    What is the second workflow supposed to be moving to the trash?

    As previously mentioned, you do not need the Get Folder Contents or Get Selected Finder Items actions, since items added to the attached folder are automatically passed to the folder action workflow. Your usage of the Get Selected Finder Items action would seem to indicate that you have the wrong idea about what Automator actions do. In an Automator workflow, the result of any given action is passed on to the input of the following action - you can see what an action outputs and expects for input in its description.
     
  5. Nor*Cal thread starter macrumors regular

    Joined:
    Jun 17, 2007
    Location:
    Irvine, CA
    #5
    The second workflow will move the empty folders it finds to the trash (after the movie file within it is moved, from action 1).

    I know that it is not necessary to have some of the steps in there, but they worked and so I left them, I can remove them. I just don't know if it's possible to combine the two existing actions.
     
  6. Red Menace macrumors 6502

    Joined:
    May 29, 2011
    Location:
    Littleton, Colorado, USA
    #6
    Well, the main problem I see is that if the folder the movie is in is the one that has the folder action attached to it, removing the folder will remove the folder action. Are you adding a folder (or folders) containing other files and folders? If so, you need to step back and describe exactly what you are wanting to do with all of the items dropped onto the folder, including those that are not moved.

    The Get Selected Finder Items action will do just what its name says, and should really be removed to prevent unexpected results, since the action will add any selected Finder items to the folder action items.
     
  7. Nor*Cal thread starter macrumors regular

    Joined:
    Jun 17, 2007
    Location:
    Irvine, CA
    #7
    I'm only trying to move the folders within.

    Essentially I'm trying to do the following:

    1. Extract all file types that are movie
    2. Move the movie files to another folder
    3. Delete all other files that are not movies or folders that do not contain movie files after steps 1 and 2 are complete.
     
  8. Red Menace macrumors 6502

    Joined:
    May 29, 2011
    Location:
    Littleton, Colorado, USA
    #8
    That kind of workflow can be done by using variables. For example, the following workflow filters out movie files and copies those to another folder, then moves everything to the trash. I'm using the copy action because it is easier to just make copies than try to split things up into different lists, but you can use more variables to store different filtered lists if desired. The copy action is supposed to wait for the copy to complete, but I don't have a lot of large files around to test with, so you might want to keep an eye on it while testing:

    1) Folder action receives files and folders added to { your attached folder }
    2) Get Folder Contents { Repeat for each subfolder found } -- expand any contained items
    3) Set Value of Variable { Variable: Original Items} -- save for later
    4) Filter Finder Items { Kind is Movie } -- filter out those items to move...
    5) Copy Finder Items { To: your destination folder } -- ...and move them
    6) Get Value of Variable { Variable: Original Items } (Ignore Input) -- get the original list back
    7) Move Finder Items to Trash

    Note that the Ignore Input option is used on the Get Value of Variable action in step 6 - this is to prevent the paths of the previously copied items (which are returned from the copy action) from getting mixed in with the original list that is about to get trashed.
     
  9. Nor*Cal thread starter macrumors regular

    Joined:
    Jun 17, 2007
    Location:
    Irvine, CA
    #9
    Thank you for the help! However after testing these are my results:
    1. Dropping individual movie file by itself into Folder 1 — Works
    2. Dropping movie file within another folder into Folder 1 — Works, but doesn't delete original folder
     
  10. Red Menace macrumors 6502

    Joined:
    May 29, 2011
    Location:
    Littleton, Colorado, USA
    #10
    Try swapping steps 2 and 3, so that the Original Items variable is set to the input items before getting any folder contents.
     
  11. Nor*Cal thread starter macrumors regular

    Joined:
    Jun 17, 2007
    Location:
    Irvine, CA
    #11
    That did the trick!

    One last thing, I decided to simplify things even more, and add my shell script which does the following:
    1. Uses ffmpeg to convert the extracted movie file to mp4
    2. Moves the movie file to another folder
    3. Trashes the original movie file

    [​IMG]

    The bash script and action work correctly, however for some reason whenever the dropped filetype is mp4, the empty folder is not deleted. When I drop a mkv, or a movie without a parent folder, everything runs smoothly. Any ideas? For the most part it's working as expected, thank you very much!
     

Share This Page