You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Help with Automator

I use SketchUp extensively and would like to write a workflow to get rid of backup files. SketchUp will auto backup files by appending a tilde to the end of the file name, ie WoodPart.skp becomes Wood~art~.skp as a backup. This is a very useful features, but leaves a lot of unneeded backups. Using SmartSearch I can easily locate all of them using "~.skp" in the search field. I saved that search and use it often to clean out old unused backups. I tried the same approach with Automator but can't find the magic command to select only files with "~.skp" in them. Does anyone have a suggestion? I am a total neophyte using Automator so there is probably something very basic I am missing. Thanks in advance for any advice.

MacBook Pro 15″, macOS 12.6

Posted on Oct 7, 2022 12:45 PM

Reply
15 replies

Oct 8, 2022 3:20 AM in response to orvilleph

I see this as a two-action Automator solution.

  1. Ask for Finder Items
  2. Run Shell Script


The following Automator application solution was tested on macOS 12.6. It also writes a text file of the removed SketchUp backfiles that it removes to your Desktop. The contents of the Run Shell Script should be:


#!/bin/zsh

: <<"COMMENT"

Provided a folder containing SketchUp backup files (~.skp), report and
remove them.

Reference: https://discussions.apple.com/thread/254266583
Tested: macOS 12.6, Zsh 5.8.1
VikingOSX, 2022-10-08, Apple Support Communities, No warranties expressed/implied.
COMMENT

REPORT_FILE="$HOME/Desktop/SketchUp_backups.txt"
STARTDIR="${@:a:s/\~\//}"

function SketchUp_backup_filter () {
    # Each file is represented by the REPLY variable
    # and when a match occurs (true) pass the current file
    # into the for-loop.
    [[ $REPLY =~ "~\.skp" ]]
}

function report () {
    print -Dl "${1}" >> $REPORT_FILE
}

today="$(date -j +"%F %X")"
printf '%s - %s\n\n' "SketchUp Backup Files Removed" $today > $REPORT_FILE

# case-insensitive regular files
setopt nocaseglob
for f in ${STARTDIR}/*.skp(.N+SketchUp_backup_filter);
do
    report "${f}"
    rm -f "${f}"
done
exit 0


And the finished Automator workflow looks like this:


Oct 8, 2022 11:44 AM in response to orvilleph

Ensure that you are creating a new Automator application.


That Ask for Finder Items action should be set as shown in my post. You select the folder (not its contents) that contains your SketchUp files and that will pass that folder path into the Run Shell Script action.


You select the boilerplate content in the Run Shell Script and remove it — before copying/pasting the code above into that action. You set the shell and pass input on that Run Shell Script action as you see in my previous post so that the folder path passed in from the Ask for Finder Items action (as $@) is assigned to the STARTDIR variable.


I just copied the code that I posted above into a new Automator Application, and it works first try to remove the SketchUp backup file in a test folder and write the report which follows:


Oct 10, 2022 11:56 AM in response to Camelot

Thank you for your suggestion. I duplicated the actions you used, but I must be doing something wrong. When I click Workflow>Run I get a prompt to supply the folder name I want to use. When I do that it runs, but produces no results. I attached screenshots of the script I used, one showing the prompt for folder and one with the results which you can see in the log. As I mentioned in my original message I am a newbie at this so I am not sure what to try next.


Oct 10, 2022 3:48 PM in response to Camelot

There is currently only one ~.skp file in the directory, I cleaned out the others a couple of days ago. Could it be that Automator can't read the iCloud Directory. I noticed in the "Ask for Finder Items" step there is a folder listed in a format I don't recall seeing before. I took a screenshot of that. I looks normal in the listing when I hover over the box, but what's in the box looks odd. You can see that in the second attached screenshot.

Oct 8, 2022 7:09 AM in response to VikingOSX

Thanks again for your help.


I started a new Automator doc using "Ask for Finder Items" and then added "Run Shell script" as you suggest. I then copied/pasted the terminal steps from your reply into the Automator file. When I hit Workflow>Run it does run, but it does not delete the ~.skp files and consequently the txt file is blank. Could it be that I need to specify the folder first?


Also, it also asks me for a location to save the txt file, no big deal but is it possible to add something to eliminate that step?

Oct 12, 2022 5:00 PM in response to orvilleph

> I tried copying one of the ~.skp files to a local directory then ran the Automator and it worked


Odd. iCloud Drive does some weird tricks with directories, but I don't see anything obvious. I'll poke it here.


> The only hiccup was the prompt to select the folder


I'm not sure what hiccup you're referring to. The action 'Ask for Finder Items' is going to prompt for a folder - that's exactly what it does. If you want to process a predefined folder and not have to select it every time, replace this action with Get Specified Finder Items where you can choose the folder in advance.

Help with Automator

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.