Using KM for weekly exporting a text file list of all files in a specific folder

Hi all

I would love to get some suggestion from the community on a way to weekly export via km (cron?) actions a plain text list of all files in a directory (at start all my music files from either the music folder or even from music (iTunes).)

I want this in order to have a “soft” backup of my files so that in case of a nuclear emergency where all my backups fail I can restore my music library. Does that make any sense :wink:?

to be clear I don't want to backup any files but rather just create a list of all files in a text file

What options do you guys think will work?

thx

Z

@zeltak - This works for me for the folder list at least. For the individual files, within the individual subfolders of the main folder, a guru will have to take it to the next step.

image

See if this gets you close.

KC

just to complement Kc, you can have KM run it weekly using the Periodic Trigger

Thanks @hello

I think I’d change it to a time of day trigger since he only wants it weekly.

https://wiki.keyboardmaestro.com/trigger/Time_of_Day

1 Like

Hi, it's TJ the "here's a shell script" guy saying "Here's a shell script".

There are a few options. The first is ls (that's a lowercase LS).

For example, if I type:

ls ~/Music/

then I will get this back as an answer:

Audio Hijack Music ffatp

Now, as it turns out, those 3 things are actually folders not files, and inside those folders are files (and additional folders).

If we want to keep going inside those folders, we need to use the -R flag to ls to recursively list all of the folders. While we're at it, we might want to use -F which also tries to give some indication what each entry is, such as a / at the end of folder names:

If I do ls -FR ~/Music then

Audio Hijack/
Music/
ffatp/

/Volumes/tjluoma/Music/Audio Hijack:
ATP.fm-2020-02-26-at-20-58.mp3

/Volumes/tjluoma/Music/Music:
Media.localized/
Music Library.musiclibrary/

/Volumes/tjluoma/Music/Music/Media.localized:
Automatically Add to Music.localized/
Downloads-Music/
Steven Curtis Chapman/

/Volumes/tjluoma/Music/Music/Media.localized/Automatically Add to Music.localized:

/Volumes/tjluoma/Music/Music/Media.localized/Downloads-Music:

/Volumes/tjluoma/Music/Music/Media.localized/Steven Curtis Chapman:
Live from Sweetwater Studios Sessions/

/Volumes/tjluoma/Music/Music/Media.localized/Steven Curtis Chapman/Live from Sweetwater Studios Sessions:
I Will Be Here.mp3

/Volumes/tjluoma/Music/Music/Music Library.musiclibrary:
Application.musicdb
Extras.itdb
Genius.itdb
Library Preferences.musicdb
Library.musicdb
Preferences.plist
sentinel

/Volumes/tjluoma/Music/ffatp:
ATP 2020-02-26.mp3

That‘s not bad but I think what you really want is better handled by find because with find you can say “Show me only files, not folders or anything else, and show me the full path to each file.”

The way that you do that is like this:

find ~/Music -type f -print

(-type f means “just files”)

If I do that then I get something that looks like this:

/Volumes/tjluoma/Music/Music/Media.localized/.Media Preferences.plist
/Volumes/tjluoma/Music/Music/Media.localized/.localized/id.strings
/Volumes/tjluoma/Music/Music/Media.localized/.localized/es.strings
/Volumes/tjluoma/Music/Music/Media.localized/.localized/no.strings
/Volumes/tjluoma/Music/Music/Media.localized/.localized/zh_TW.strings
/Volumes/tjluoma/Music/Music/Media.localized/.localized/fi.strings
/Volumes/tjluoma/Music/Music/Media.localized/.localized/ru.strings
/Volumes/tjluoma/Music/Music/Media.localized/.localized/en.strings
/Volumes/tjluoma/Music/Music/Media.localized/.localized/es_419.strings
/Volumes/tjluoma/Music/Music/Media.localized/.localized/he.strings
/Volumes/tjluoma/Music/Music/Media.localized/.localized/uk.strings
/Volumes/tjluoma/Music/Music/Media.localized/.localized/fr_CA.strings
/Volumes/tjluoma/Music/Music/Media.localized/.localized/nl.strings
/Volumes/tjluoma/Music/Music/Media.localized/.localized/de.strings
/Volumes/tjluoma/Music/Music/Media.localized/.localized/ja.strings
/Volumes/tjluoma/Music/Music/Media.localized/.localized/sk.strings
/Volumes/tjluoma/Music/Music/Media.localized/.localized/hr.strings
/Volumes/tjluoma/Music/Music/Media.localized/.localized/el.strings
/Volumes/tjluoma/Music/Music/Media.localized/.localized/th.strings
/Volumes/tjluoma/Music/Music/Media.localized/.localized/zh_CN.strings
/Volumes/tjluoma/Music/Music/Media.localized/.localized/cs.strings
/Volumes/tjluoma/Music/Music/Media.localized/.localized/sv.strings
/Volumes/tjluoma/Music/Music/Media.localized/.localized/pl.strings
/Volumes/tjluoma/Music/Music/Media.localized/.localized/zh_HK.strings
/Volumes/tjluoma/Music/Music/Media.localized/.localized/en_GB.strings
/Volumes/tjluoma/Music/Music/Media.localized/.localized/en_AU.strings
/Volumes/tjluoma/Music/Music/Media.localized/.localized/da.strings
/Volumes/tjluoma/Music/Music/Media.localized/.localized/fr.strings
/Volumes/tjluoma/Music/Music/Media.localized/.localized/ro.strings
/Volumes/tjluoma/Music/Music/Media.localized/.localized/pt.strings
/Volumes/tjluoma/Music/Music/Media.localized/.localized/pt_PT.strings
/Volumes/tjluoma/Music/Music/Media.localized/.localized/ms.strings
/Volumes/tjluoma/Music/Music/Media.localized/.localized/ko.strings
/Volumes/tjluoma/Music/Music/Media.localized/.localized/hu.strings
/Volumes/tjluoma/Music/Music/Media.localized/.localized/hi.strings
/Volumes/tjluoma/Music/Music/Media.localized/.localized/tr.strings
/Volumes/tjluoma/Music/Music/Media.localized/.localized/vi.strings
/Volumes/tjluoma/Music/Music/Media.localized/.localized/ca.strings
/Volumes/tjluoma/Music/Music/Media.localized/.localized/ar.strings
/Volumes/tjluoma/Music/Music/Media.localized/.localized/it.strings
/Volumes/tjluoma/Music/Music/Media.localized/Steven Curtis Chapman/Live from Sweetwater Studios Sessions/I Will Be Here.mp3
/Volumes/tjluoma/Music/Music/Media.localized/Automatically Add to Music.localized/.localized/id.strings
/Volumes/tjluoma/Music/Music/Media.localized/Automatically Add to Music.localized/.localized/es.strings
/Volumes/tjluoma/Music/Music/Media.localized/Automatically Add to Music.localized/.localized/no.strings
/Volumes/tjluoma/Music/Music/Media.localized/Automatically Add to Music.localized/.localized/zh_TW.strings
/Volumes/tjluoma/Music/Music/Media.localized/Automatically Add to Music.localized/.localized/fi.strings
/Volumes/tjluoma/Music/Music/Media.localized/Automatically Add to Music.localized/.localized/ru.strings
/Volumes/tjluoma/Music/Music/Media.localized/Automatically Add to Music.localized/.localized/en.strings
/Volumes/tjluoma/Music/Music/Media.localized/Automatically Add to Music.localized/.localized/es_419.strings
/Volumes/tjluoma/Music/Music/Media.localized/Automatically Add to Music.localized/.localized/he.strings
/Volumes/tjluoma/Music/Music/Media.localized/Automatically Add to Music.localized/.localized/uk.strings
/Volumes/tjluoma/Music/Music/Media.localized/Automatically Add to Music.localized/.localized/fr_CA.strings
/Volumes/tjluoma/Music/Music/Media.localized/Automatically Add to Music.localized/.localized/nl.strings
/Volumes/tjluoma/Music/Music/Media.localized/Automatically Add to Music.localized/.localized/de.strings
/Volumes/tjluoma/Music/Music/Media.localized/Automatically Add to Music.localized/.localized/ja.strings
/Volumes/tjluoma/Music/Music/Media.localized/Automatically Add to Music.localized/.localized/sk.strings
/Volumes/tjluoma/Music/Music/Media.localized/Automatically Add to Music.localized/.localized/hr.strings
/Volumes/tjluoma/Music/Music/Media.localized/Automatically Add to Music.localized/.localized/el.strings
/Volumes/tjluoma/Music/Music/Media.localized/Automatically Add to Music.localized/.localized/th.strings
/Volumes/tjluoma/Music/Music/Media.localized/Automatically Add to Music.localized/.localized/zh_CN.strings
/Volumes/tjluoma/Music/Music/Media.localized/Automatically Add to Music.localized/.localized/cs.strings
/Volumes/tjluoma/Music/Music/Media.localized/Automatically Add to Music.localized/.localized/sv.strings
/Volumes/tjluoma/Music/Music/Media.localized/Automatically Add to Music.localized/.localized/pl.strings
/Volumes/tjluoma/Music/Music/Media.localized/Automatically Add to Music.localized/.localized/zh_HK.strings
/Volumes/tjluoma/Music/Music/Media.localized/Automatically Add to Music.localized/.localized/en_GB.strings
/Volumes/tjluoma/Music/Music/Media.localized/Automatically Add to Music.localized/.localized/en_AU.strings
/Volumes/tjluoma/Music/Music/Media.localized/Automatically Add to Music.localized/.localized/da.strings
/Volumes/tjluoma/Music/Music/Media.localized/Automatically Add to Music.localized/.localized/fr.strings
/Volumes/tjluoma/Music/Music/Media.localized/Automatically Add to Music.localized/.localized/ro.strings
/Volumes/tjluoma/Music/Music/Media.localized/Automatically Add to Music.localized/.localized/pt.strings
/Volumes/tjluoma/Music/Music/Media.localized/Automatically Add to Music.localized/.localized/pt_PT.strings
/Volumes/tjluoma/Music/Music/Media.localized/Automatically Add to Music.localized/.localized/ms.strings
/Volumes/tjluoma/Music/Music/Media.localized/Automatically Add to Music.localized/.localized/ko.strings
/Volumes/tjluoma/Music/Music/Media.localized/Automatically Add to Music.localized/.localized/hu.strings
/Volumes/tjluoma/Music/Music/Media.localized/Automatically Add to Music.localized/.localized/hi.strings
/Volumes/tjluoma/Music/Music/Media.localized/Automatically Add to Music.localized/.localized/tr.strings
/Volumes/tjluoma/Music/Music/Media.localized/Automatically Add to Music.localized/.localized/vi.strings
/Volumes/tjluoma/Music/Music/Media.localized/Automatically Add to Music.localized/.localized/ca.strings
/Volumes/tjluoma/Music/Music/Media.localized/Automatically Add to Music.localized/.localized/ar.strings
/Volumes/tjluoma/Music/Music/Media.localized/Automatically Add to Music.localized/.localized/it.strings
/Volumes/tjluoma/Music/Music/.DS_Store
/Volumes/tjluoma/Music/Music/Music Library.musiclibrary/Application.musicdb
/Volumes/tjluoma/Music/Music/Music Library.musiclibrary/Extras.itdb
/Volumes/tjluoma/Music/Music/Music Library.musiclibrary/sentinel
/Volumes/tjluoma/Music/Music/Music Library.musiclibrary/Library.musicdb
/Volumes/tjluoma/Music/Music/Music Library.musiclibrary/Genius.itdb
/Volumes/tjluoma/Music/Music/Music Library.musiclibrary/Library Preferences.musicdb
/Volumes/tjluoma/Music/Music/Music Library.musiclibrary/Preferences.plist
/Volumes/tjluoma/Music/ffatp/ATP 2020-02-26.mp3
/Volumes/tjluoma/Music/.localized
/Volumes/tjluoma/Music/Audio Hijack/.DS_Store
/Volumes/tjluoma/Music/Audio Hijack/ATP.fm-2020-02-26-at-20-58.mp3

If you want more detail about each file, use:

find ~/Music -type f -ls (change -print to -ls).

If you want the list to be sorted alphabetically, use:

find ~/Music -type f -print | sort -f

If you want the list to be sorted alphabetically and include a blank line between each line (which can make it much easier to read if you have a lot of long times), use:

find ~/Music -type f -print | sort -f | sed G

If you want all of that, and you want it to save the output to a file, try this:

#!/usr/bin/env zsh -f

PATH='/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin'

zmodload zsh/datetime

TIME=$(strftime "%Y-%m-%d--%H.%M.%S" "$EPOCHSECONDS")

find "$HOME/Music" -type f -print | sort -f | sed G \
> "$HOME/Desktop/Music-File-List-as-of-$TIME.txt"

exit 0

Every time that script runs, the list of files will be saved to your ~/Desktop/ but you can change that by changing $HOME/Desktop/ ($HOME is just another way of referring to your home folder where all of your files appear in Finder.) For example you could change it to $HOME/Dropbox/ if you wanted it stored in Dropbox instead. Just make sure the folder exists.

You could copy/paste that script into Keyboard Maestro and have it run every Sunday at 12:30 p.m. (or whenever) using the Time of Day trigger that has already been suggested.

That's what this macro does.

Index-Files-in-Music-Folder.kmmacros (2.3 KB)

It does Sunday and Wednesday, just because. You can set it to whatever times/days you'd like.

Let me know if you have questions/problems/etc.

4 Likes

nice! a script by TJ, the script guy (TM) :+1:

your music library needs more Heavy Metal :slight_smile:

My music library is actually Apple Music, so there's almost nothing in my local Music folder :slight_smile:

1 Like

Thx @tjluoma and all others

that’s perfect and exactly what I needed, KM community for the win again! :slight_smile:

really appreciated (and also really cool after hearing your great podcast on MPU yesterday :))!!

best

Z

1 Like