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.

  • Well, you could raise a terminal window from script and print stuff there. You could also display a small popup with zenity that shows the script is working. One can also write a "progress" popup, either with zenity or in Python via Gtk API, but that's overly complex for a nautilus script I'd say. – Sergiy Kolodyazhnyy Jul 28 '17 at 18:13
  • Sometimes script output to the terminal ends up in /var/log/syslog when run in GUI. However @SergiyKolodyazhnyy hasn't pointed out to me before this isn't always the case. – WinEunuuchs2Unix Jul 28 '17 at 18:23
  • This is probably totally overdoing things, but https://askubuntu.com/a/757599/72216. Used it to notice if and when my rsync backup was running :). Just to mention. – Jacob Vlijm Jul 28 '17 at 18:42

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,734
  • 1
  • 21
  • 38