Okay, I'm stumped.
December 1, 2007 5:39 PM   Subscribe

Scriptfilter: I want a list of filenames dumped into text file and put somewhere. How!?

Okay, so I've gotten religious about backing up my HDD, but I don't waste the space backing up my applications, aside from a few important ones. Instead, I'd prefer just a list of the files inside my Application folder so I can go and download them if I need to.

Soooo, is there any way that I can write a script that will 1) grab the names of all the files in a specific folder, 2) dump all the file names into a text file (or similar,) and 3) save that folder where ever I so choose.

I'm on a Mac, if it matters at all (AppleScript, or whatnot)
posted by InsanePenguin to Computers & Internet (10 answers total)
Best answer: I'm sure the Mac gurus will soon come along and tell you how to do it with the GUI, but a linux nut would just go out to the terminal (also available in OSX) and type:

ls -1 /Applications/ > filelist.txt

where filelist.txt will go to the current directory, but can easily be put anywhere by adding the path to the front of it. The -1 provides a list with each app on a separate line.
posted by ranglin at 6:01 PM on December 1, 2007

Response by poster: Geez, that was incredibly quick.

Thanks alot, the Terminal works just fine.
posted by InsanePenguin at 6:05 PM on December 1, 2007

You might want to look at find. It allows to do things like; exclude files with the execute bit set, exclude or include files of a specific type such as excluding directories but including plain files and so on.

Also, keeping lists of what files have been backed up and when is an incredible pain. That, and I'm sure that as I type the gods are preparing to nuke every byte of un-backed up data I own, is what backup programs are for.
posted by rdr at 6:15 PM on December 1, 2007

Response by poster: All of my important user files and, hence, anything vitally important, is backed up automatically. All I really want a list of is the apps that I have downloaded, so I don't forget to get them again if I ever need to. Nothing vital here, just convenience.
posted by InsanePenguin at 6:50 PM on December 1, 2007

In that case, why not put the ls -1 command into your crontab so it runs automatically every day, or once an hour even?
posted by kindall at 7:22 PM on December 1, 2007

Best answer: Ranglin's command won't recurse into subdirectories, if you've organized any applications into folders. Using bash (which I think is the default shell on osx) or a few other shells you can use an extended wildcard syntax:

ls -1d /Applications/**/*.app

will list all '.app' bundles in /Applications, including in subfolders. The -d flag to ls tells it not to display the contents of each .app (since an application on osx is actually a directory containing the program plus its many associated files) but to just list the .app itself.

You can run shell scripts from Applescript using the 'do script' command, FYI, in case you want to invoke all this from an applescript.
posted by hattifattener at 7:30 PM on December 1, 2007

Huh, is that extended wildcard syntax something that Apple added? I've never heard of such a thing and can't seem to find documentation on the web. If that doesn't work for subfolders of subfolders of subfolders, use the find command as rdr suggests:
find /Applications -name '*.app'
posted by grouse at 12:54 AM on December 2, 2007

No, the "**" extended glob pattern is reasonably widespread in the Unix world now. (It does go arbitrarily deep, so my example would, for example, find applications embedded inside other applications— rare but not unheard-of on OSX.)

I have a vague feeling that it showed up in zsh around the turn of the century, and is now in zsh, ksh, and bash (at least). Tcsh doesn't seem to have it.
posted by hattifattener at 12:46 PM on December 2, 2007

I'm using bash 3.2, the latest version (not on a Mac), and don't seem to have this feature, nor does it seem to be mentioned in the bash documentation. Maybe it's a hack Apple added.
posted by grouse at 1:05 PM on December 2, 2007

Hmmm, I think you're right. I tested it on an openbsd system, and thought it handed the ** syntax too, but I see I tested it wrong. :) (In any case, Apple presumably got it from zsh.)
posted by hattifattener at 3:16 PM on December 2, 2007

« Older How long is waitlist at WMA or CAA?   |   Gay Male Fiction Help Newer »
This thread is closed to new comments.