harvey Posted April 8, 2016 Posted April 8, 2016 (edited) A simple command to Flush DNS cache. Compatible with 10.6 through to 12.0. Takes no arguments but asks for system password to run the task as an admin user. Available on packal.org Any issues, please let me know. Update 04/08/2021: Added support for macOS Monterey 12.0. Commands remain the same based on early Betas. Update 12/12/2020: Bug Fix Update 06/12/2020: Support for macOS Big Sur 11.0 - Re-written code. Also allowed future to use the current command if it remains valid without future release Update 22/12/2019: Support for macOS Catalina 10.15 Update 20/1/2019: Support for macOS Mojave 10.14 Update 20/4/2018: Updated icon Update 24/1/2018: Support for macOS High Sierra 10.13 Update 12/1/2017: Support for macOS Sierra 10.12 Edited August 4, 2021 by harvey Update 04/08/2021: Added support for macOS Monterey 12.0. Commands remain the same based on early Betas. 40-02, Dolge and andmetoo 3
FroZen_X Posted April 8, 2016 Posted April 8, 2016 I have some problems with my DNS lately so this could help hopefully tyvm for sharing
harvey Posted May 3, 2016 Author Posted May 3, 2016 Awesome workflow! Thanks! No problems, glad it helped
harvey Posted January 12, 2017 Author Posted January 12, 2017 Update 12/1/2017: Support for macOS Sierra 10.12
CKIDOW Posted January 5, 2018 Posted January 5, 2018 Hi, I updated the script for Mac OS High Sierra and just added these lines of code: elif [ ${array[1]} -eq 13 ]; then echo "Version ${ver} is macOS High Sierra" osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges' The final script is: #!/bin/bash # ver="10.11.1" ver=`sw_vers -productVersion` IFS='.' read -r -a array <<< "$ver" # echo ${array[0]} # echo ${array[1]} # echo ${array[2]} # if [ -z ${array[2]} ];then # echo "You have not installed any sub update" # fi if [ ${array[1]} -eq 6 ]; then echo "Version ${ver} is Snow Leopard" osascript -e 'do shell script "sudo dscacheutil -flushcache" with administrator privileges' elif [ ${array[1]} -eq 7 ] || [ ${array[1]} -eq 8 ] || [ ${array[1]} -eq 9 ]; then echo "Version ${ver} is one of the following: Lion, Mountain Lion or Mavericks" osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges' elif ([ ${array[1]} -eq 10 ] && [ -z ${array[2]} ]) || ([ ${array[1]} -eq 10 ] && [ ${array[2]} -le 3 ]); then echo "Version ${ver} is Yosemite and 10.10.3 or less" osascript -e 'do shell script "sudo discoveryutil mdnsflushcache" with administrator privileges' elif [ ${array[1]} -eq 10 ] && [ ${array[2]} -ge 4 ]; then echo "Version ${ver} is Yosemite and 10.10.4 or higher" osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges' elif [ ${array[1]} -eq 11 ]; then echo "Version ${ver} is El Capitan" osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges' elif [ ${array[1]} -eq 12 ]; then echo "Version ${ver} is macOS Sierra" osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges' elif [ ${array[1]} -eq 13 ]; then echo "Version ${ver} is macOS High Sierra" osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges' else echo "Version ${ver} is Unknown" exit 1 fi
harvey Posted January 24, 2018 Author Posted January 24, 2018 Thanks @CKIDOW . This has now been updated on Packal to support 10.13 High Sierra here http://www.packal.org/workflow/flush-dns-106-1011
iLeopard Posted March 29, 2018 Posted March 29, 2018 Thank you for posting this. It proves to be quite useful when performing intense loads.
harvey Posted March 31, 2018 Author Posted March 31, 2018 On 3/29/2018 at 8:49 AM, iLeopard said: Thank you for posting this. It proves to be quite useful when performing intense loads. Your very welcome
xilopaint Posted April 2, 2018 Posted April 2, 2018 The color of the icon doesn't suit well in Alfred dark themes. Please, consider to change the icon's color to suit both light and dark themes or add an option to change the icon according the theme.
harvey Posted April 18, 2018 Author Posted April 18, 2018 On 02/04/2018 at 3:24 AM, xilopaint said: The color of the icon doesn't suit well in Alfred dark themes. Please, consider to change the icon's color to suit both light and dark themes or add an option to change the icon according the theme. I'm not much of a designer. If your able to provide an icon I'm happy to consider it.
deanishe Posted April 18, 2018 Posted April 18, 2018 Dude, the icon's perfect. It's just the colour that needs changing.
harvey Posted April 19, 2018 Author Posted April 19, 2018 (edited) Do the attached look any better @deanishe @xilopaint? Dark and light themes, highlighted and not variations? Edited April 19, 2018 by harvey
harvey Posted April 19, 2018 Author Posted April 19, 2018 35 minutes ago, deanishe said: Where's the toilet gone? Down the pan! deanishe 1
harvey Posted April 19, 2018 Author Posted April 19, 2018 41 minutes ago, deanishe said: Where's the toilet gone? Best I can do I'm afraid..
harvey Posted April 20, 2018 Author Posted April 20, 2018 18 hours ago, deanishe said: Where's the toilet gone? @deanishe @xilopaint Updated workflow with the new icon. deanishe and xilopaint 2
deanishe Posted April 20, 2018 Posted April 20, 2018 Awesome. As long as the toilet's still there. It's literally my favourite workflow icon. harvey 1
bigorno Posted January 16, 2019 Posted January 16, 2019 Hi, for macOS Mojave (10.14.x) : #!/bin/bash ver=`sw_vers -productVersion` IFS='.' read -r -a array <<< "$ver" if [ ${array[1]} -eq 6 ]; then echo "Version ${ver} is Snow Leopard" osascript -e 'do shell script "sudo dscacheutil -flushcache" with administrator privileges' elif [ ${array[1]} -eq 7 ] || [ ${array[1]} -eq 8 ] || [ ${array[1]} -eq 9 ]; then echo "Version ${ver} is one of the following: Lion, Mountain Lion or Mavericks" osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges' elif ([ ${array[1]} -eq 10 ] && [ -z ${array[2]} ]) || ([ ${array[1]} -eq 10 ] && [ ${array[2]} -le 3 ]); then echo "Version ${ver} is Yosemite and 10.10.3 or less" osascript -e 'do shell script "sudo discoveryutil mdnsflushcache" with administrator privileges' elif [ ${array[1]} -eq 10 ] && [ ${array[2]} -ge 4 ]; then echo "Version ${ver} is Yosemite and 10.10.4 or higher" osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges' elif [ ${array[1]} -eq 11 ]; then echo "Version ${ver} is El Capitan" osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges' elif [ ${array[1]} -eq 12 ]; then echo "Version ${ver} is macOS Sierra" osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges' elif [ ${array[1]} -eq 13 ]; then echo "Version ${ver} is macOS High Sierra" osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges' elif [ ${array[1]} -eq 14 ]; then echo "Version ${ver} is macOS Mojave" osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges' else echo "Version ${ver} is Unknown" exit 1 fi
harvey Posted January 20, 2019 Author Posted January 20, 2019 Thanks @bigorno. I have updated logic to support 10.14 Mojave. New version is on Packal. Used a slightly better method:- #!/bin/bash ver=`sw_vers -productVersion` IFS='.' read -r -a array <<< "$ver" if [ ${array[1]} -eq 6 ]; then echo "Version ${ver} is Snow Leopard" osascript -e 'do shell script "sudo dscacheutil -flushcache" with administrator privileges' elif [ ${array[1]} -ge 7 -a ${array[1]} -le 9 ]; then echo "Version ${ver} is Lion, Mountain Lion or Mavericks" osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges' elif ([ ${array[1]} -eq 10 ] && [ -z ${array[2]} ]) || ([ ${array[1]} -eq 10 ] && [ ${array[2]} -le 3 ]); then echo "Version ${ver} is Yosemite and 10.10.3 or less" osascript -e 'do shell script "sudo discoveryutil mdnsflushcache" with administrator privileges' elif [ ${array[1]} -eq 10 ] && [ ${array[2]} -ge 4 ]; then echo "Version ${ver} is Yosemite and 10.10.4 or higher" osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges' elif [ ${array[1]} -ge 11 -a ${array[1]} -le 14 ]; then echo "Version ${ver} is El Capitan, Sierra, High Sierra or Mojave" osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges' else echo "Version ${ver} is Unknown" exit 1 fi
Pierpaolo Posted December 22, 2019 Posted December 22, 2019 Added Catalina (simple as 123 thanks to @harvey! ) #!/bin/bash ver=`sw_vers -productVersion` IFS='.' read -r -a array <<< "$ver" if [ ${array[1]} -eq 6 ]; then echo "Version ${ver} is Snow Leopard" osascript -e 'do shell script "sudo dscacheutil -flushcache" with administrator privileges' elif [ ${array[1]} -ge 7 -a ${array[1]} -le 9 ]; then echo "Version ${ver} is Lion, Mountain Lion or Mavericks" osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges' elif ([ ${array[1]} -eq 10 ] && [ -z ${array[2]} ]) || ([ ${array[1]} -eq 10 ] && [ ${array[2]} -le 3 ]); then echo "Version ${ver} is Yosemite and 10.10.3 or less" osascript -e 'do shell script "sudo discoveryutil mdnsflushcache" with administrator privileges' elif [ ${array[1]} -eq 10 ] && [ ${array[2]} -ge 4 ]; then echo "Version ${ver} is Yosemite and 10.10.4 or higher" osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges' elif [ ${array[1]} -ge 11 -a ${array[1]} -le 14 ]; then echo "Version ${ver} is El Capitan, Sierra, High Sierra or Mojave" osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges' elif [ ${array[1]} -ge 14 -a ${array[1]} -le 15 ]; then echo "Version ${ver} is Catalina" osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges' else echo "Version ${ver} is Unknown" exit 1 fi
harvey Posted December 22, 2019 Author Posted December 22, 2019 2 hours ago, Pierpaolo said: Added Catalina (simple as 123 thanks to @harvey! ) #!/bin/bash ver=`sw_vers -productVersion` IFS='.' read -r -a array <<< "$ver" if [ ${array[1]} -eq 6 ]; then echo "Version ${ver} is Snow Leopard" osascript -e 'do shell script "sudo dscacheutil -flushcache" with administrator privileges' elif [ ${array[1]} -ge 7 -a ${array[1]} -le 9 ]; then echo "Version ${ver} is Lion, Mountain Lion or Mavericks" osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges' elif ([ ${array[1]} -eq 10 ] && [ -z ${array[2]} ]) || ([ ${array[1]} -eq 10 ] && [ ${array[2]} -le 3 ]); then echo "Version ${ver} is Yosemite and 10.10.3 or less" osascript -e 'do shell script "sudo discoveryutil mdnsflushcache" with administrator privileges' elif [ ${array[1]} -eq 10 ] && [ ${array[2]} -ge 4 ]; then echo "Version ${ver} is Yosemite and 10.10.4 or higher" osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges' elif [ ${array[1]} -ge 11 -a ${array[1]} -le 14 ]; then echo "Version ${ver} is El Capitan, Sierra, High Sierra or Mojave" osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges' elif [ ${array[1]} -ge 14 -a ${array[1]} -le 15 ]; then echo "Version ${ver} is Catalina" osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges' else echo "Version ${ver} is Unknown" exit 1 fi Thanks @Pierpaolo for the reminder. I have updated the logic to support 10.15. New version is on Packal.
harvey Posted December 5, 2020 Author Posted December 5, 2020 On 12/4/2020 at 9:58 PM, Samplex said: @harveyAny update for Big Sur? Working on a small re-write. Should be out this weekend. Thanks
harvey Posted December 6, 2020 Author Posted December 6, 2020 (edited) On 12/4/2020 at 9:58 PM, Samplex said: @harveyAny update for Big Sur? I have released a new version. The code has been completely re-written so please let me know if there are any issues. I have also added logic to support 11.1+ so if the current command does not change, it should to continue to work without requiring an update. Please ensure you use v2.0.1 Updated link is https://www.packal.org/workflow/flush-dns-106-110 Edited December 6, 2020 by harvey Added Link
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now