Show Image Notification from Bash Script

Show image notification from bash script

gcin does the work. It shows full size images as notifications.

sudo apt-get install gcin
gcin-message -icon your_image.jpg

Extract of man gcin-message:

gcin-message - gcin's notification tool

gcin-message [-icon file] [-text string] [-duration milliseconds]

gcin-message displays notification image and/or text. It is useful for
filters to have interaction with users.

-icon file
Display an image.

-text string
Display text string. The space character is not allowed.

-duration milliseconds
Time to show notifications.

However I suggest you to not use this tool, because its installation from the Ubuntu repository is not fine grained (6 MB of stuff and a chinese icon in the notification area).

See if you can get gcin-message out of the gcin package and put it into your own package (if this suits your needs).

How to show a GUI message box from a bash script in linux?

I believe Zenity will do what you want. It's specifically designed for displaying GTK dialogs from the command line, and it's available as an Ubuntu package.

Bash script for a slideshow with image list refresh

watch -n 300 -t `find -type f | egrep -i "(jpg|bmp|png|gif)$"`

What this is doing, because you've used backticks, is passing the list of filenames to watch, which I suspect you don't want to do. Maybe this would work, but I don't have any way to test:

watch -n 300 -t '/usr/bin/fbi -noverbose -a -t 4 -u `find -type f | egrep -i "(jpg|bmp|png|gif)$"`'

Though this brings up the thorny question of just how many copies of fbi will be running after a few days.

Probably your best bet would be to set up a cron job to run a script like this every x minutes:

pkill -f /usr/bin/fbi
shopt globstar
cd /your/images/directory
files=(**/*.jpg **/*.bmp **/*.png **/*.gif)
usr/bin/fbi -noverbose -a -t 4 -u "${files[@]}"

Instead of using find and grep, I used bash globbing, which is safe for filenames with spaces, and also saves you running two other commands! This requires bash 4+ for the globstar option that provides recursive matching.

The globbing gives you file names in an array, which is passed directly to fbi, as described in Bash FAQ 50

Use terminal to display image without losing focus

Here is a not-too-awkward solution using wmctrl:

wmctrl -T master$$ -r :ACTIVE: ; display image.png & sleep 0.1 ; wmctrl -a master$$

To explain, I'll break it down into steps:

  1. wmctrl -T master$$ -r :ACTIVE:

    To control a window, wmctrl needs to know its name, which by default is its window title. So, this step assigns the current window to a unique name master$$ where the shell will expand $$ to a process ID number. You may want to choose a different name.

  2. display image.png &

    This step displays your image as a "background" process. The image window will grab focus.

  3. sleep 0.1

    We need to wait enough time for display to open its window.

  4. wmctrl -a master$$

    Now, we grab focus back from display. If you chose a different name for your master window in step 1, use that name here in place of master$$.

If wmctrl is not installed on your system, you will need to install it. On debian-like systems, run:

apt-get install wmctrl

wmctrl supports Enlightenment, icewm, kwin, metacity, sawfish, and all other EWMH/NetWM compatible X-window managers.

Alternative approach that doesn't require knowing the window title

First, get the ID of the current window:

my_id=$(wmctrl -l -p | awk -v pid=$PPID '$3 == pid {print $1}')

We can now use this ID in place of a window title. To launch display while maintaining focus in the current window:

display image.png & sleep 0.1 ; wmctrl -i -a "$my_id"

Show a dialog with a text input field and an image in AppleScript

AppleScript’s native dialog display facilities (aka display dialog and display alert) are rather limited and won’t allow you to display an image, unless you define it as an OS X icon file (.icns) of the right size, which might not be very practical for a captcha.

However, there is at least one alternative I am aware of: Carsten Blüm’s Pashua will allow you to create native Cocoa dialogs containing both textfield and image elements. As these are defined in a DSL and created by Pashua, they can be used straight from a shell script (no need to interpose AppleScript – check out the documentation and example shell script distributed with Pashua).

How to display an image just for a few seconds and close it?

How about this dirty method? :

display -density 200 -hold 3 myvector.eps &
sleep 10
kill -2 $pid

ImageMagick, Bash script to label with comment and image sequence number

I would do it something like this, using a MIFF to append individually labelled files to an output stream then read them all from stdin into the montage command:

for f in /tmp/*-thumb.jpg; do
convert -label "$i Comment %f" "$f" miff:-
done | montage - \
-frame 5 \
-tile 3x3 \
-geometry +10+10 \
-background black \

They come out looking like this:

Sample Image

Conditions for the icon for notify-send -i

Try using the absolute path of the icon, i.e.:

notify-send "message" --icon="~/Desktop/USERNAME/image.png"


notify-send "message" --icon="$HOME/Desktop/USERNAME/image.png"

Related Topics

Leave a reply