MacOS Image Background remove with Automator

If you need to remove the background from multiple images, MacOS Automator does not provide a background removal action out of the box but the existing tools from MacOS can be combined to provide a solution to create a flexible batch job.

Since MacOS 15.x (Sequoia) provides the following manual options to remove the background from Images:

Preview App

MacOS Preview App
[MacOS Preview App]

Finder Shortcut "Remove Background"

Finder Shortcut Remove Background
[Finder Shortcut Remove Background]

**Note: the Finder Shortcut supports the transformation of multiple selected images! Use this if you do not need any control on output folder or file name.

Automator Solution

  1. Open Automator and create a new document
  2. Choose Application as the document type
  3. the first Action will be a short AppleScript to move an existing target folder to the trash folder. Add Action Utilities -> Execute AppleScript
1on run {input, parameters}
2
3 tell application "Finder"
4 -- Define the folder path
5 set folderPath to (path to downloads folder as text) & "Images with removed Background"
6
7 -- Check if the folder exists
8 if exists folder folderPath then
9 -- Delete the folder
10 delete folder folderPath
11 end if
12 end tell
13
14 return input
15end run
  1. Add Action Files & Folders -> New Folder to create a new Folder Images with removed Background in the downloads folder. Any Image or Folder dragged on this Automation will be copied to this folder.
  2. Add Action Files & Folders -> Get Folder Contents and select the option Repeat for each subfolder found
  3. Add Action Photos -> Change Type of Image. Cancel the dialog which asks you to add an additional action to copy the images before changing the type. This is not needed, as the images in the new folder are already copies of the original images. The format change is required as the Preview.app will replace the removed background with a transparent layer which is not supported by the JPEG format.
  4. Add Action Utilities -> Execute AppleScript
1-- Wichtig! In Systemeinstellungen -> Datenschutz & Sicherheit
2-- muss die App "Bilderfreistellen" unter Bedienungshilfen und
3-- die App "Vorschau" unter Festplattenvollzugriff gelistet sein
4on run {input, parameters}
5 tell application "Preview"
6 activate
7 repeat with imgFile in input
8 -- Open the image file in Preview
9 open imgFile
10
11 -- Wait for Preview to fully open the file
12 delay 1
13
14 -- Send the "Shift + Command + K" keyboard shortcut
15 tell application "System Events"
16 keystroke "k" using {shift down, command down}
17 end tell
18
19 -- Wait for the command to finish processing
20 delay 1
21
22 -- Save and close the file
23 tell application "Preview"
24 close document 1 saving yes
25 end tell
26 end repeat
27 end tell
28 tell application "Finder"
29 -- Define the folder path
30 set folderPath to (path to downloads folder as text) & "Images with removed Background"
31
32 -- Check if the folder exists
33 if exists folder folderPath then
34 -- Show the folder
35 open folderPath
36 end if
37 end tell
38 return input
39end run
  1. Save the Automator document under Image Background Removal

The last AppleScript will iterate over all images in all subfolders. The background ist removed with the tool provided by the Preview.app. When finished the the created folder with the transformed images will be opened in the Finder.

To provide this Automation with the required access rights you will need to:

  1. add the Image Background Removal App to System Preferences -> Privacy & Security -> Accessibility (you will need to redo this if you change your Automation App!)
  2. add the App Preview.app to System Preferences -> Privacy & Security -> Full Disk Access
  3. allow your Image Background Removal App to control Finder, Preview and System Events - which will add it to System Preferences -> Privacy & Security -> Automation

To use this Automation drag one or multiple images or folders with images on this automation.