2

I have written a code in python language that usage subprocess.call() method and print method, i am using this code as nautilus script and it is working fine. but there is no way to know that script is working right now, i can see the effect only after script completed.

I want this script to run in terminal so that i can know that script is running and there is a print method in the code that need to be print text when script fail but it does not shows up.

If there is other method than terminal please tell me.

1 Answers1

0

Here is small snippet in bash, you can easy rewrite in python, it notify user trying to find a possible way:

#!/usr/bin/env bash

have_command() {
  type -p "$1" >/dev/null
}

try() {
  have_command "$1" && "$@"
}

in_terminal() {
  [ -t 0 ]
}

notify_user() {
  local msg="${2:-Error}: $1"
  echo "$msg" >&2
  in_terminal && return
  try notify-send "$msg" && return
  try yad --info --text="$msg" && return
  try zenity --info --text="$msg" && return
  try xmessage -buttons Ok:0 -nearmouse "$msg" -timeout 10 && return
  return
}

Install notify-send and you'll get nice messages

LeonidMew
  • 2,802