Latest in Applescript

Image credit:

Friday Favorite: Use AppleScript to delete files from a folder


As part of my daily writing, I take a lot of screenshots and process a ton of images on my Mac. As a result, I have two ever-growing folders that are stuffed full of images that are not useful after I publish a post. Now that I have a MacBook Air and only 128 GB of storage space, I am much more concerned about keeping my files in check.

To help delete these files in bulk, I've been using this handy AppleScript:


tell application "Finder"

delete (every item of folder (path to desktop folder) whose name begins with "Screen Shot")

delete (every item of folder (path to downloads folder) whose name ends with ".jpg")

end tell

on error

display dialog ("Error. Couldn't Move the File") buttons {"OK"}

end try

You can modify it yourself to point to a different folder or to target different files. If you remove the qualifier "whose name begins with" and leave the line as "delete (every item of folder (path to desktop folder))", then you can delete all the contents of a folder in one fell swoop.

I don't need to run the script every day, so I've exported it as an application and run it once a week. It's not a fancy script, but it is a timesaver, which makes it invaluable for me. Hopefully, it will be of use to you, too.

From around the web