On Jan 2, 2015, at 11:30 AM, Alex Hall < email@hidden> wrote: A friend asked me to hack together a script that will copy the names of all the files in the current folder *and* any subfolders. I'm still in the beginning stages, making sure I have the right terms and such. Here's my script so far:
tell application "Finder" set currentDir to (target of front window) display dialog (currentDir as text) & " has " & ((currentDir's items) count) & " items." repeat with f in currentDir's items display dialog name of f & "< " & (size of f as text) repeat with p in properties of f display dialog p as text end repeat end repeat end tell
The problem is that, once that first display dialog appears and I dismiss it, Finder pops up instead of the Script Editor, and no other display dialog runs. It's as though Finder is showing me that front window instead of executing the "repeat" statements, for some reason. The path and count the initial dialog shows are correct, so that's working. Why then is Finder appearing, and no dialogs displaying at all?
Hi Alex,
Luther has given you some good ideas. Here are some more thoughts for you.
I think your problem may be one of dereferencing. You're trying to get a property (name or size) of a reference (repeat with f) to a reference (items) to a reference (currentDir's). Trying to coerce such a convoluted beast to a string is asking a lot of AS. Luther was able to adjust the AS terminology to make things work. But, instead, I'd recommend converting data to simpler forms (strings, integers) as early as you can, rather than keeping it as references.
What you want the script to accomplish is rather fuzzy. We'd need a clearer description before we could be of much help. Nevertheless, there are many, many ways to do similar things. Using the Finder, here's one example of a starting point:
tell application "Finder" set currentDir to (target of front window) set {allNames, allSizes, allConts} to {name, size, container} of (entire contents of currentDir) repeat with i from 1 to (count allNames) set {thisName, thisSize, thisCont} to {item i of allNames, item i of allSizes as string, item i of allConts as string} -- do something here end repeat end tell
Related: if something like this already exists, can someone let me know and save me the time? I don't mind doing it, but I'd rather not re-invent the wheel. Thanks!
IMO, the grunt work of re-inventing the wheel (or inventing some all-new thingamajig) is what puts experience under your belt and will, in time, make you a good scripter. It's messy, frustrating, and takes some time, but the result IS worthwhile.
Regards, Stan C.
|