Rules Scripting Sample

Summary: Demonstrates how to control SpamSieve’s rules using AppleScript.
Requires: SpamSieve
Install Location: ~/Library/Scripts/SpamSieve Scripts/
Last Modified: 2018-06-07


This script demonstrates how to control SpamSieve’s blocklist and whitelist using AppleScript.

The order of the words in the corpus is undefined, so to save a particular word you should remember its string, not its index.

Using get every word (and other operations on very large numbers of words) will not work, because AppleScript runs out of memory.

Installation Instructions · Download in Compiled Format · Download in Text Format


tell application "SpamSieve"
-- Prune unused blocklist rules; this will be very slow if there
-- are lots of rules, so you might want to use a "with timeout" block.
-- It would be faster to do this using the the Blocklist window.
tell blocklist
delete (every rule whose hits is 0)
end tell
-- Look up a rule by its text and enable it
tell whitelist
-- there may be more than one rule with this text
set l to every rule whose text to match is ""
set r to item 1 of l
set r's isEnabled to true
end tell
-- Makes a new blocklist rule that matches messages with zip
-- attachments.
tell blocklist
make rule with properties {text to match:".zip", match field:any attachment name, match style:ends with style}
end tell
-- Easily make blocklist rules that match the From address.
tell blocklist
add sender rules for addresses {"", ""}
end tell
end tell