0

I would like to have a simple script to notify the user in the screen, each time a new folder or file is created in a shared folder. The output should be like "You have a new file/folder named newfile/newfolder". I'm using this script, but I'm not able to put the newfile/newfolder name in zenity output.

while inotifywait -r -e create ~/Documents/Process
do
    zenity --warning -- ????
done

thks Djames

1 Answer 1

2

You can try a similar script:

while true
do
    fileName=$(inotifywait -r -e create ~/Documents/Process | sed -r 's/^.*CREATE(,ISDIR)*\s+(.*)$/\2/g')
    zenity --warning --text="You have a new file/folder named $fileName"
done

The fileName variable holds the extracted file name that inotifywait detects and outputs. (It is filtered from the output by using a sed command.)

Then the $fileName is displayed by zenity using the --text= switch.

These two lines run in an endless loop to enable detection of other creation events. Use CTRL + C to abort the watch.

5
  • thks! It works!, but I'll make some more tests to check if everything is ok!
    – DJames
    Jun 8, 2012 at 8:35
  • I'm glad you've found it useful! I've tested it with some weird filenames, but make sure to comment on any problems.
    – lgarzo
    Jun 8, 2012 at 8:40
  • Ok, a little more complicated. I've looking in sed manual, what you have donne, but I'could understand quite well...the inotify can have 3 outputs: "CREATE" (file), "CREATE,ISDIR" (directory), or empty when deleting file ou folder. The important output is the text right next to "CREATE" or "CREATE,ISDIR". Can you help? thks!
    – DJames
    Jun 8, 2012 at 19:03
  • @Djames Updated for directory detection, sorry for the inconvenience.
    – lgarzo
    Jun 9, 2012 at 13:43
  • thks very much, it's working! ;)
    – DJames
    Jun 11, 2012 at 22:45

You must log in to answer this question.

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