projectz

Tech, Gadgets, Photography, Social Media and Poor Spelling

Relaunch a dead Google Drive Session on a Mac.?

Download Installer

I’ ve put this script together it checks to see if the Google Drive service is still running, if it is, no worries however if Google Drive has died, it will either wait for immediate human interaction to click OK, or if you are not around will restart the service after 30 seconds anyway. It’s the 1st draft.. however works on my OSX Lion MBP..

If nothing else, it’s an example of source, running a function in the back ground, how to create a popup dialog on a Mac from a script and how to launch an OSX App from the command line

I’m sure we can do this better.. any help appreciated.

#!/bin/sh

SERVICE=”Google Drive”

end1=”0”

 echo “Service is $SERVICE”

TEMPFILE=”temp.txt”

 echo “temp file is $TEMPFILE”

echo “end1=0” > $TEMPFILE

func_countdowntime(){

echo “getting here”

while [ $end1 = “0” ];

        do

                echo “countdown started”

                for i in $(seq 10 -1 1);

                do 

                echo $i && sleep 3;

                echo “end is $end1”

                if [ $end1 = “1” ];

                        then

                        echo “Stop Countdown”

                        break

                fi 

                . $TEMPFILE

                done

                killall osascript

                echo “Open $SERVICE”

        done

echo “help”

}

func_check(){

if ps -ax | grep -v grep | grep “$SERVICE”

then

    echo “$SERVICE service running, everything is fine”

else

        #runs a cuntdown script in the background which will restart in 30 seconds anyway

        func_countdowntime &

        osascript -e ‘tell app “System Events” to display dialog “Google Drive not running nClick OK to restart now nGoogle Drive will restart automatically in 30 Seconds”’

        if [ $? = 0 ] ; then

                echo “end1=1” > $TEMPFILE

                open “/Applications/Google Drive.app”

        else

                echo “end1=1” > $TEMPFILE

                echo “Nothing to do, move along..”

        fi

fi

}

while :

        do

                func_check

                sleep 10

                echo “end=0” > $TEMPFILE

        done

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Information

This entry was posted on May 7, 2012 by in regular and tagged , , , , , , , , , .
%d bloggers like this: