0
votes

I'm trying to create a simple script to delete files based on a custom label I've already assign.

I'm currently trying to limit the search for the script to a test folder, but ultimately I want the script to search in all the user folder and get all the files from several different locations. I may need authentication for the process.

But so far I have this

tell application "Finder" delete (every item of folder "/users/ro/documents/Erase test" whose label is "test") end tell

and I get this error

error "Finder got an error: Can’t get folder \"/users/ro/documents/Erase test\"." number -1728 from folder "/users/ro/documents/Erase test"

As I said I don't really know much about scripts, so I don't know all the terms but I hope someone can point me in the right direction.

1

1 Answers

0
votes

Saw this late. Tested this on 10.6.8 and will jump on a Mavericks machine to test, but this should work:

set f to choose folder

tell application "Finder"
    delete (every item of f whose label index is 1)
end tell

A few notes about your attempt: 1) AppleScript doesn't 'natively' understand POSIX paths (but coercion to/from is possible), so (as I have it) "choose folder" returns what is known as an alias (not to be confused with a string -- but again, coercions to/from strings/aliases are simple). 2) note that the label is recognized as "label index", which is an integer. 3) you could/should test by taking out "delete" in that line to return a list of those items.

[edit] yes, this is fine on Mavericks.