macosbashosx-yosemitehackintosh

OS X: Run script (or app) on a post-upgrade reboot


I'm trying to find a programmatic solution for a friend of mine, who operates a Hackintosh system, or OS X installed on non-Macintosh Intel computers. Whenever he is installing a Mac OS X security update, he needs to re-patch his audio drivers using MultiBeast. So, I was thinking about doing this automatically, given that Apple offers a way to hook a script post_upgrade (which I'm unaware of).


Solution

    1. Create a file with the following script:
    #!/bin/bash
    
    CURR_VERSION="$(sw_vers -buildVersion)"
    PREV_VERSION="$(cat ~/.previous-version)"
    
    if [ "$CURR_VERSION" != "$PREV_VERSION" ]; then
      # Do stuff here
    
      echo "$CURR_VERSION" > ~/.previous-version
    fi
    
    1. chmod +x it
    2. sudo nano /Library/LaunchDaemons/version-checker.plist
    3. Type in:
    <?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">
    <dict>
        <key>Label</key>
        <string>version-checker</string>
        <key>ProgramArguments</key>
        <array>
            <string>/path/to/your/check_version.sh</string>
        </array>
        <key>StartInterval</key>
        <integer>60</integer>
        <key>RunAtLoad</key>
        <true/>
    </dict>
    </plist>
    
    1. Save with CTRL+X, Y
    2. sudo launchctl load /Library/LaunchDaemons/version-checker.plist