dcmichael dcmichael - 3 years ago 269
AppleScript Question

Need Script To Automatically Restart Mac Until Negotiated SATA Link Speed is SATA II

I've got a couple of late 2009 Mac Minis running Mavericks. I recently replaced their hard drives with SSDs. Everything seems to work fine, however, I don't always get SATA II speeds. The computer often negotiates down to SATA I speeds. If I restart the computer enough times, it will eventually register at SATA II speeds and I'm good to go.

I don't think there's an elegant solution to the problem, but is there a script available, or that someone could write, that on start-up would check my negotiated SATA link Speed, and if it's less than 3.0GBPS it would automatically restart the computer and loop until it reads out the appropriate speed?

Thanks! Any help would be appreciated

Answer Source

If I found myself in the situation you've described, and could not replace the hardware, I'd set up a bash script to check the SATA Negotiated Link Speed of the SSD and if it's less than 3, reboot until it's not less then 3.

Here is an example of what I'd do:


  • This was tested under a clean install of macOS Sierra 10.12.6, where, by default, /usr/local/bin does not exist, so the target directory needs to be created first.
  • The bash script is named snls, standing for: SATA Negotiated Link Speed
  • As coded, this assumes you have only one SATA SSD and no other SATA devices connected. If you have more than one, the awk command will need to be modified as necessary.
  • The only difference in the code presented herein and what was tested is -lt 3 was set to -lt 7, because on my system 6 is the normal value of the output to the command on the left side of the -lt operator, and by setting it to 7 it rebooted until the expression was modified from Recovery Mode to enable a normal boot, where I changed it to -lt 6 so it would then boot normally. Having no issue with my system, this was the only way to test this.

In Terminal, execute the following commands to setup the bash script and Launch Daemon that will check the SATA Negotiated Link Speed of the SSD:

sudo mkdir -p /usr/local/bin
sudo touch /usr/local/bin/snls
sudo nano /usr/local/bin/snls

In nano, either type or copy and paste the following:


[[ $(system_profiler SPSerialATADataType | awk '/Negotiated Link Speed:/{print $4}') -lt 3 ]] && shutdown -r now

Save the changes and exit nano by pressing the following key sequences:

Still in Terminal:

Make snls executable, only to root:

sudo chmod 744  /usr/local/bin/snls

Create the Launch Daemon .plist file for snls:

sudo touch /Library/LaunchDaemons/com.sata.snls.plist
sudo nano /Library/LaunchDaemons/com.sata.snls.plist

Copy and paste the following into nano:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">

Save the changes and exit nano by pressing the following key sequences:

Load the Launch Daemon:

sudo launchctl load /Library/LaunchDaemons/com.sata.snls.plist

With this set, each time you boot and the SATA Negotiated Link Speed of the SSD is less than 3, it's going to reboot until it's 3, however many times it takes.

WARNING: Do not undertake this process unless you know how to boot to Recovery Mode and that Recovery Mode is working on your system, or have an alternate method to access and modify the filesystem on the SSD. Also, you are comfortable in Recovery Mode Terminal to navigate to either target file created and delete them so you can reboot normally if something is not working, e.g. stuck in an endless reboot loop, with this method on your system.

Have a look at: About macOS Recovery

Note that when booted to macOS Recovery and you start Terminal, it's not like when you open Terminal in a normal boot. You are not by default in your normal Home directory, and typing cd / doesn't take you to the root of the e.g. Macintosh HD, you'd be in the root of OS X Base System. Also, nano is not in the PATH used by Terminal in macOS Recovery, although it's available if you type the proper path filename.

When you open Terminal under macOS Recovery the PWD is /private/var/root, so to get to e.g. Macintosh HD, you type: cd /Volumes/Macintosh\ HD

Again, if you have an issue with this method, deleting either snsl or com.sata.snls.plist from macOS Recovery will allow the system to boot normally, whatever normally is for you.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download