iCloud file manipulation shortcuts

I am using hazel to transfer new CSV files generated from a web application to an iCloud folder. I would like to write a shortcut that could tally or count the number of files added each day. Ultimately will use this data for other calculations. Not sure I see how to count files in a folder in shortcuts. Any suggestions would be appreciated

Also I would like to make another shortcut that could be triggered to run daily by a notification or alarm that would import the data from each new CSV file into data jar. I figured out how to import into data jar but cant seem to think of best way to ensure its repeating import for each new file in the folder and of course not duplicating import of files already imported. Any suggestions would be appreciated.

You can solve your first problem using Scriptable and its File/Folder Bookmarks feature. Settings > File Bookmarks

Create a bookmark for the folder you are watching. You can then reference that folder in a script.

Here is a really basic example script named “Count Files”

let fm = FileManager.iCloud()
// reference folder bookmark created in Scriptable
let dir = fm.bookmarkedPath("Temp")
let contents = fm.listContents(dir)
let num_files = contents.length
new CallbackURL("shortcuts://").open()

The following shortcut shows how to call the script and use the results.

I imagine there are more elegant solutions, but this may get you started

1 Like

It is worth noting you can achieve the same by using the Scriptable Run Inline Script action.

Example Shortcut