Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make the screen Flash from Mac OS Terminal

I using different build scripts for package my apps. Some of them running a while and it would be great to have a visual notification the script is ready.

I already use the notifications center with an Apple Script but something it is not alarming enough. Is it possible to run and Applescript or a command line command to let the screen flashes. A plus would be to flash in different colors (green for OK and red for build failed).

like image 813
Tobias Redmann Avatar asked Oct 30 '25 07:10

Tobias Redmann


1 Answers

I have a couple of ideas...

Easiest:

Go to Terminal->Preferences->Advanced and change to Visual Bell then do

tput bel

Coolest:

Here is a little scipt I wrote to save the current Desktop background and then set it to green for 3 seconds and then reset it back to what it was. Of course, if you like it you can make it do red for fail pretty simply. All you need to do is save the red.jpg and free,jpg files below in the /Library/Desktop Pictures folders as red.jpg and green.jpg. Then save the script below as notify and make it executable with:

chmod +x notify

and run it with

./notify

Here is the script:

#!/bin/bash

# Function to save current wallpaper
saveWallpaper(){
osascript<<EOF
tell application "Finder"
    set theDesktopPic to desktop picture
    set theName to displayed name of theDesktopPic
    return theName
end tell
EOF
}

# Function to set the wallpaper
setWallpaper(){
echo $1
osascript<<EOF
set desktopImage to POSIX file "/Library/Desktop Pictures/$1"
tell application "Finder"
    set desktop picture to desktopImage
end tell
EOF
}

# Start of actual script

# Save current wallpaper
saved=$(saveWallpaper)
echo Wallpaper is: $saved

# Set wallpaper to green for 3 seconds
setWallpaper "green.jpg"
sleep 3

# Restore wallpaper
setWallpaper "$saved"

Using some sound:

For success:

osascript -e 'beep 1'

For fail:

osascript -e 'beep 3'

Or how about:

afplay /System/Library/Sounds/Ping.aiff -v 2

enter image description here enter image description here

like image 166
Mark Setchell Avatar answered Nov 01 '25 12:11

Mark Setchell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!