Skip to content

Instantly share code, notes, and snippets.

@funasoul
Last active December 2, 2021 17:28
Show Gist options
  • Save funasoul/43ccfbf588868486f7d2d130765bc60c to your computer and use it in GitHub Desktop.
Save funasoul/43ccfbf588868486f7d2d130765bc60c to your computer and use it in GitHub Desktop.
Return 0 if dropbox is running.
is_dropbox_running() {
# Return 0 if dropbox is running.
# Thanks to Official Dropbox Command Line Interface.
# https://www.dropboxwiki.com/tips-and-tricks/using-the-official-dropbox-command-line-interface-cli
if [[ -r ~/.dropbox/dropbox.pid ]]; then
pid=$(cat ~/.dropbox/dropbox.pid)
else
return 1
fi
if [[ "$OSTYPE" == "linux-gnu" ]]; then
# Linux
if [[ -f /proc/${pid}/cmdline ]]; then
grep -qi dropbox /proc/${pid}/cmdline
return $?
else
return 1
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
# macOS
ps -p $pid -o command | grep -qi dropbox.app
return $?
else
# Unknown.
return 1
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment