Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

sampdoria

macrumors regular
Original poster
Jun 14, 2010
136
0
Unloading and reloading the discoveryd service seems to keep network connectivity for a few hours or so. Can someone write an AppleScript that refreshes the discoverd service by unloading and reloading it periodically, let's say every 120 minutes or so? I have a MacMini as a media server, always on, that is dropping network connectivity constantly and would benefit from this until Apple comes out with a proper fix. The reocurring script would go something like:

1. open Terminal

2. enter the following command (to unload discoverd):
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.discoveryd.plist
3. Hit return and enter admin password (to use the sudo command)

4. enter the following command (to reload discoverd):
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.discoveryd.plist
5. Hit return to finish the command

6. close Terminal

Many thanks in advance!
 

Wowzera

macrumors 6502a
Oct 14, 2008
858
28
Brazil
Can't you create a shell script and make an automator action to open it every X minutes? You already have the commands to write a shell script.
 

sampdoria

macrumors regular
Original poster
Jun 14, 2010
136
0
Can't you create a shell script and make an automator action to open it every X minutes? You already have the commands to write a shell script.

I'd love to, if you can show me how :) thank you

----------

Don't need Applescript. Just "sudo su" to become root, create a text file with your two commands (no sudo needed) and add it to root's cron.

Can you walk me through this please? Can I undo or delete it when Apple issues a fix? Thank you.
 

deathdruid

macrumors member
Oct 24, 2006
38
2
Cambridge, MA, USA
Sorry, this process is a bit involved if you are not comfortable with the Terminal. I don't have time to write it all up, but here are the basics:

1. Save your two commands (without sudo) to a text file, name it "restart_discoveryd.sh" or something similar and make it executable (use Get Info on the file).
2. In Terminal, become root (the superuser account) by doing:
Code:
sudo su
and entering your password. For this to work, the user you are has to be an admin account.
3. Again in Terminal, do:
Code:
crontab -e
Hopefully that brings up an editor you are comfortable with (if not, try "set EDITOR=nano"), and you can enter a cron entry that runs your script. For instance, you might enter:
Code:
*/5 * * * * /home/CoolGuy/restart_discoveryd.sh >/dev/null 2>&1
to run the script "/home/CoolGuy/restart_discoveryd.sh" every 5 minutes and disable email notifications of what happened. More help on cron is at Crontab Quick Reference.

The Automator route would be easier, but I am not sure how to sudo in Automator, being a Unix guy myself.

----------

Oh, and to stop running this script by cron, repeat the same process but delete the line you put in when you did "crontab -e".
 
Last edited:

sampdoria

macrumors regular
Original poster
Jun 14, 2010
136
0
Wow, thank you deathdrruid. The crontab quick reference link is also very helpful. I'll give this a try later today. Just one question: how exactly do you do step 1 (make a text file into an executable file)?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.