Can someone write an AppleScript to fix Yosemite Wifi issues?

Discussion in 'OS X Yosemite (10.10)' started by sampdoria, Nov 10, 2014.

  1. sampdoria macrumors regular

    Joined:
    Jun 14, 2010
    #1
    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!
     
  2. Wowzera macrumors 6502a

    Joined:
    Oct 14, 2008
    Location:
    Brazil
    #2
    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.
     
  3. deathdruid macrumors member

    Joined:
    Oct 24, 2006
    Location:
    Baltimore, MD
    #3
    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.
     
  4. sampdoria thread starter macrumors regular

    Joined:
    Jun 14, 2010
    #4
    I'd love to, if you can show me how :) thank you

    ----------

    Can you walk me through this please? Can I undo or delete it when Apple issues a fix? Thank you.
     
  5. deathdruid, Nov 11, 2014
    Last edited: Nov 11, 2014

    deathdruid macrumors member

    Joined:
    Oct 24, 2006
    Location:
    Baltimore, MD
    #5
    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".
     
  6. sampdoria thread starter macrumors regular

    Joined:
    Jun 14, 2010
    #6
    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)?
     
  7. deathdruid macrumors member

    Joined:
    Oct 24, 2006
    Location:
    Baltimore, MD
    #7
    At the terminal:

    Code:
    chmod +x filename.sh
    Sorry, I thought you could do it with Finder, but I only see "Read" and "Write" there. For a general intro to Unix on Mac OS X, see this nice writeup by Hayne.
     

Share This Page