As Apple restricted extensions' capabilities, an alternative approach might more effective. The hosts file can be used to block acces to defined domains, thus preventig every application from accesing it. By using custom lists of domains, ads and malware can be blocked.
GitHub user Dani3lSun wrote a simple and efective script: adblock_hosts.sh Mac OS X adblock shell script using system hosts file (Block ads system wide) https://gist.github.com/Dani3lSun/83ebfa77fbb21a6873ef but it hasn't been updated in a while.
I made minor changes, updating the links, ading NoCoin adblock list and a line to remove the temporary directory created. My version can be found here https://gist.github.com/b0gdanw/2716bc05be8eef49424b105d39370105
Usage:
1. Download https://gist.githubusercontent.com/...46847c0e2a4bc302b099727c230b/adblock_hosts.sh in your home folder
Or open Terminal and run
2. Change file permissions to executable
3. Run
(Alternatively, you can skip step 2 and run sudo bash adblock_hosts.sh)
The script downloads six text files containing the domains to be blocked, merges them into one, renames the original hosts file to hosts_org and copies the new host file to /private/etc/hosts
The original and the hosts file created are also saved in the home folder as hosts_org.txt and hosts_new.txt
To revert to the original hosts file
and to flush DNS cache
Advantages:
- no resources used
- applies to every application (Safari, Chrome, Mail and any other that connects to the Internet)
Disadvantages:
- it has to be manually updated
- no whitelist or possibility to disable for certain sites
Further reading
About the hosts file https://en.wikipedia.org/wiki/Hosts_(file)
Idea for the script and source for the lists AdAway for Android https://github.com/AdAway/AdAway
Other domain lists:
NoCoin adblock list https://github.com/hoshsadiq/adblock-nocoin-list
StevenBlack/hosts https://github.com/StevenBlack/hosts
Application to manage hosts file:
Gas Mask - simple hosts file manager for macOS https://github.com/2ndalpha/gasmask
GitHub user Dani3lSun wrote a simple and efective script: adblock_hosts.sh Mac OS X adblock shell script using system hosts file (Block ads system wide) https://gist.github.com/Dani3lSun/83ebfa77fbb21a6873ef but it hasn't been updated in a while.
I made minor changes, updating the links, ading NoCoin adblock list and a line to remove the temporary directory created. My version can be found here https://gist.github.com/b0gdanw/2716bc05be8eef49424b105d39370105
Usage:
1. Download https://gist.githubusercontent.com/...46847c0e2a4bc302b099727c230b/adblock_hosts.sh in your home folder
Or open Terminal and run
Code:
curl -O https://gist.githubusercontent.com/b0gdanw/2716bc05be8eef49424b105d39370105/raw/fe06ab01309746847c0e2a4bc302b099727c230b/adblock_hosts.sh
2. Change file permissions to executable
Code:
chmod +x adblock_hosts.sh
3. Run
Code:
sudo ./adblock_hosts.sh
(Alternatively, you can skip step 2 and run sudo bash adblock_hosts.sh)
The script downloads six text files containing the domains to be blocked, merges them into one, renames the original hosts file to hosts_org and copies the new host file to /private/etc/hosts
The original and the hosts file created are also saved in the home folder as hosts_org.txt and hosts_new.txt
To revert to the original hosts file
Code:
sudo rm -f /private/etc/hosts; sudo mv /private/etc/hosts_org /private/etc/hosts
Code:
dscacheutil -flushcache
Advantages:
- no resources used
- applies to every application (Safari, Chrome, Mail and any other that connects to the Internet)
Disadvantages:
- it has to be manually updated
- no whitelist or possibility to disable for certain sites
Further reading
About the hosts file https://en.wikipedia.org/wiki/Hosts_(file)
Idea for the script and source for the lists AdAway for Android https://github.com/AdAway/AdAway
Other domain lists:
NoCoin adblock list https://github.com/hoshsadiq/adblock-nocoin-list
StevenBlack/hosts https://github.com/StevenBlack/hosts
Application to manage hosts file:
Gas Mask - simple hosts file manager for macOS https://github.com/2ndalpha/gasmask
Last edited: