I want to display a notification using osascript in terminal, but the text I want to display is stored in a text file. How can I display that text in the notification?

3 Answers 3


In the Bash shell, you can read in the text of the file using cat and shove it into a substitution.

Something like:

osascript -e "display notification \"$(cat /tmp/foo.txt)\" with title \"hello\""

(Obviously put something in /tmp/foo.txt first, like echo "Hello world" > /tmp/foo.txt)


Basically you need to read the file content into a variable first. There are several ways to do this, one is

text=$(< TEXTFILE)
osascript ... "$text"
  • so there's no way to do it in a one-liner?
    – Kwright02
    Nov 23, 2017 at 15:45
  • Sure, just replace the variable with the $(...) construct
    – nohillside
    Nov 23, 2017 at 19:19

Here is the complete soloution to my initial question I posted about:

set listOfCommand to (read POSIX file "path-to/command.txt")
  tell application "Terminal"
    do script listOfCommand
    delay 1
  end tell
set listOfShows to (read POSIX file "path-to/dump.txt")
 tell application "Safari"
    display notification listOfShows with title "Downloads:"
 end tell

You must log in to answer this question.

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