2

Is there a terminal command I can use to quit Google's "Backup and Sync" software? I am writing a Bash script to set the machine up for maximum battery life and I would like to shutdown all non-essential software that I usually have running in the background such as Backup and Sync. I tried the usual suspects (osascript -e 'tell app "Backup and Sync from Google" to quit' AND killall 'Backup and Sync from Google') without success.

3

Weird, just tried killall "Backup and Sync from Google" and it failed.

Try killall Backup\ and\ Sync, that worked for me for some reason. Adding \ from seems to break things.

| improve this answer | |
  • Thanks, that seemed to work. Do you know if the killall command allows the process to exit gracefully? – Rumboogy Dec 3 '17 at 0:29
  • By default, killall sends the SIGTERM signal; though this allows the process to shut down somewhat gracefully, it's not the same as Quit or Force Quit, nor as graceful. The AppleScript you posted is closer to what you want for a graceful exit, though I couldn't get it to work. Perhaps GUI scripting might be a solution? – JMY1000 Dec 3 '17 at 1:21
1

This post is old, but I struggled with it, so I thought I'd help. The reason the "\ from\ Google" doesn't work is because that is not what the process is, there is no "from Google in the process name. If you do:

ps -ef | grep "Backup\ and\ Sync"

You will get output like this:

501 37327 1 0 3:37PM ?? 0:06.37 /Applications/Backup and Sync.app/Contents/MacOS/Backup and Sync

It shows that the process name has no "from Google" in it. In fact, if you look in the applications directory with finder and do a "get info" it will show you the real application name. "Backup and Sync from Google" is just branding. I've seen this with other apps as well. This is ALSO what osascript also knows it as, so you can do:

osascript -e 'tell application "Backup and Sync" to activate'

and

osascript -e 'quit app "Backup and Sync"'

Which is more graceful than kill.

Note that if you have multiple users configured in Backup and Sync, you'll have to figure out the PID of the correct user, and then kill it. That's more complicated. I have a script to do that, but I don't have multiple users anymore, so not sure it still works, but for what it's worth it's below. Also don't know what the results of the osascript call is when there are multiple users.

function GoogleBackup {

if there are no parameters the error out

if [ $# -lt 1 ] then echo "$(date): Bad call of function GoogleDrive" echo "$(date): Usage:" echo "$(date): GoogleDrive [start]"
echo "$(date): GoogleDrive [killall]"
echo "$(date): GoogleDrive [stop username]"
return 0 fi

googlefound=false

case $1 in

start)

#starts Backup and Sync for all users
echo "$(date): Starting Google Backup and Sync"
open /Applications/Backup\ and\ Sync.app

;;

stop)

#stops Backup and Sync for a specified user

# if there is no username (paramenter 2) specified, exit
if [ $# -ne 2 ]
then
    echo "$(date): Incorrect parameters.  Need Google username"
    return 0
else
    #loop through each Backup and Sync user directory and look for the user to get to the PID of that process
    for path in $HOME/Library/Application\ Support/Google/Drive/user_*
    do
        # if not a directory, skip
        [ -d "${path}" ] || continue 
        dirname="$(basename "${path}")"
        #the sync_log.log file has the user name in it.  If the username is in this log file then the PID file has the process to kill
        user=$(cat $HOME/Library/Application\ Support/Google/Drive/$dirname/sync_log.log | grep "Request (" | tail -1 | awk '{print $2}' | sed 's/[)(:]//g')
        # check to see if the user in the log file matches the user specified           
        if [ "$user" == "$2" ]
        then
            #If the user matches, get the PID to kill
            pidtokill=$(cat $HOME/Library/Application\ Support/Google/Drive/$dirname/pid)
            # make sure the PID is running AND it's a Backup and Sync process (reduces risk of recycled PID)
            if ps -p $pidtokill | grep "Backup\ and\ Sync" > /dev/null
            then
                echo "$(date): Stopping backup and Sync for user $user"
                kill -quit $pidtokill
            else
                echo "$(date): Google Backup and Sync user $user is not running"
            fi
            googlefound=true
        fi
    done

    # if the specified user is not found, then log an error and provide a list of known users
    if ! $googlefound
    then
        echo "$(date): User $2 not found.  Users include:"
        for path in $HOME/Library/Application\ Support/Google/Drive/user_*
        do
            [ -d "${path}" ] || continue # if not a directory, skip
            dirname="$(basename "${path}")"
            echo "$(date): $(cat $HOME/Library/Application\ Support/Google/Drive/$dirname/sync_log.log | grep "Request (" | tail -1 | awk '{print $2}' | sed 's/[)(:]//g')"
        done
    fi
fi

;;

killall)

echo "$(date): Stopping Google Backup and Sync ALL users"
# LOG the users that are running and not running
for path in $HOME/Library/Application\ Support/Google/Drive/user_*
do
    [ -d "${path}" ] || continue # if not a directory, skip
    dirname="$(basename "${path}")"
    user=$(cat $HOME/Library/Application\ Support/Google/Drive/$dirname/sync_log.log | grep "Request (" | tail -1 | awk '{print $2}' | sed 's/[)(:]//g')
    if [ "$user" != "" ]
    then
        pidtokill=$(cat $HOME/Library/Application\ Support/Google/Drive/$dirname/pid)
        if ps -p $pidtokill |  grep "Backup\ and\ Sync"> /dev/null
        then
            echo "$(date): Stopping backup and Sync for user $user"
            googlefound=true

        else
            echo "$(date): Google Backup and Sync user $user is not running"
        fi
    fi
done
# Actually stop all users if we found any that are running, otherwise just say they are all stopped
if $googlefound
then
    killall Backup\ and\ Sync > /dev/null 
else
    echo "$(date): No Google Backup and Sync Processes were running"
fi

;;

*)

echo "$(date): Bad call of function GoogleDrive"
echo "$(date):  Usage:"
echo "$(date):  GoogleDrive [start]"    
echo "$(date):  GoogleDrive [stopall]"  
echo "$(date):  GoogleDrive [stop username]"    
return 0

;;

esac

}

(The $(date) in the echo is because this runs in the background at startup based on wifi connections and the output goes to a log file.)

Apologies if I'm not answering the "right way" as this is my first post.

| improve this answer | |
  • Oh man, been a while since I've seen an update on this question! Thanks for the additional info and scripting. – JMY1000 Jan 23 at 4:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .