commit 2b4cff77e20c60851e3f0d0335be05a06647e653
parent 8e870a1b0cb0e3bdb7ef9cee71929699ac8c8f6a
Author: Alex Balgavy <a.balgavy@gmail.com>
Date:   Tue,  4 Dec 2018 16:58:25 +0100
Make `ss-interceptor` more cross-platform
It can work on both Ubuntu-based Linux and on Mac. Not sure about
others, haven't tested it yet. But if you're using gnome-screenshot, it
will work.
Diffstat:
1 file changed, 29 insertions(+), 8 deletions(-)
diff --git a/bin/ss-interceptor b/bin/ss-interceptor
@@ -1,13 +1,15 @@
 #!/usr/bin/env bash
 
-ss_dir_orig="$(defaults read com.apple.screencapture location)"
+# Preliminary tests
+if [[ $(uname -s) == "Darwin" ]]; then
+  ss_dir_orig="$(defaults read com.apple.screencapture location)"
+elif [[ $(uname -s) == "Linux" ]] && command -v gsettings &> /dev/null; then
+  ss_dir_orig="$(gsettings get org.gnome.gnome-screenshot auto-save-directory)"  
+else
+  echo "Not supported on this system."
+  exit 1
+fi
 
-cleanup() {
-  echo "..."
-  echo "Done. Screenshots saved to $new_ss_dir."
-  defaults write com.apple.screencapture location "$ss_dir_orig"
-  exit 0
-}
 if [ $# -eq 0 ]; then
   echo "Need a new directory!"
   echo "Usage:"
@@ -15,6 +17,17 @@ if [ $# -eq 0 ]; then
   exit 1
 fi
 
+cleanup() {
+  echo "..."
+  echo "Done. Screenshots saved to $new_ss_dir."
+  if [[ $(uname -s) == "Darwin" ]]; then
+    defaults write com.apple.screencapture location "$ss_dir_orig"
+  elif [[ $(uname -s) == "Linux" ]]; then
+    gsettings set org.gnome.gnome-screenshot auto-save-directory "$ss_dir_orig"
+  fi
+  exit 0
+}
+
 trap cleanup exit
 
 echo "= Screenshot Interceptor ="
@@ -32,7 +45,15 @@ if ! [ -d "$new_ss_dir" ]; then
   echo "Creating $new_ss_dir..."
   mkdir -p "$new_ss_dir"
 fi
-defaults write com.apple.screencapture location "$new_ss_dir"
+
+if [[ $(uname -s) == "Darwin" ]]; then
+  defaults write com.apple.screencapture location "$new_ss_dir"
+elif [[ $(uname -s) == "Linux" ]]; then
+  gsettings set org.gnome.gnome-screenshot auto-save-directory "$new_ss_dir"
+else
+  echo "Error"
+fi
+
 echo "Saving screenshots to:"
 echo "$new_ss_dir"
 echo -e "\nPress Ctrl-C to stop..."