Latest in Applescript

Image credit:

Friday Favorite: Use AppleScript to delete files from a folder

Share
Tweet
Share

Sponsored Links

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:

try

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.

In this article: AppleScript, OS X
All products recommended by Engadget are selected by our editorial team, independent of our parent company. Some of our stories include affiliate links. If you buy something through one of these links, we may earn an affiliate commission.
Share
Tweet
Share

Popular on Engadget

T-Mobile’s TVision is a cable-cutting package for its mobile customers

T-Mobile’s TVision is a cable-cutting package for its mobile customers

View
Researchers 3D-printed a cell-sized tugboat

Researchers 3D-printed a cell-sized tugboat

View
'Cyberpunk 2077' is delayed again, this time to December 10th

'Cyberpunk 2077' is delayed again, this time to December 10th

View
This is Harley-Davidson's first electric bicycle

This is Harley-Davidson's first electric bicycle

View
Lenovo's Chromebook Duet with 128GB of storage falls to $249

Lenovo's Chromebook Duet with 128GB of storage falls to $249

View

From around the web

Page 1Page 1ear iconeye iconFill 23text filevr