Help with Automator action to count folder contents

Discussion in 'Mac Programming' started by patjbrown, Oct 12, 2017 at 6:32 PM.

  1. patjbrown macrumors newbie

    Joined:
    Thursday
    #1
    Hi - Im very new to scripting and im trying to build a Hazel - Automator - Script workflow that achieves the following (hazel being an If this, then do that software that monitors watch folders)


    If watch folder contains a Folder, then run automator workflow

    Automator action is

    Get Folder Contents (repeat fo each subfolder)

    Create new text file from result

    New mail containing text file

    Email text file

    Screen Cap of Workflow

    This works great to give me a list of contents, The part I need help with is how to provide a Count of the files. I can produce a list of files in the directory by using the following automator action but im really looking for a count of files inside the folder and its subdirectories.

    I had an alternate workflow that id found, which calls an apple script but the script cant find the folder im specifying, so im not sure how to direct it the input folder being fed into the automator action



    Heres that workflow

    If watch folder contains a Folder, then run automator workflow

    Automator action is

    Get Value of Variable (Path)

    Run Apple Script

    tell application "Finder"
    set theText to name of theFolder & ":" & return
    set k to 0
    repeat with thisSubfolder in (get folders of theFolder)
    set k to k + 1
    set theText to theText & (k as text) & ". " & name of thisSubfolder & ¬
    " / " & (count items in thisSubfolder) & return
    end repeat
    end tell

    Create new text file from result

    New mail containing text file

    Email text file

    Screencap of workflow

    This workflow gives the error "The variable theFolder is not defined" - So im guessing it cant find the folder I want it to count.


    Any ideas on how to feed the script the correct input location?
     

Share This Page