Add Bash variables to “osascript -e” command

When you’re using Bash scripts it’s sometimes necessary to show a window to the user asking for specific information or showing warning through AppleScript.

After a long Google search, I finally found how to add Bash variables directly into a “display dialog” window using the command “osascript-e”.Β It is sufficient to use the single quotation mark : ‘$EXAMPLE’

This example will show the Bash variable “$LAST_CONNEXION_DATE” in a window :

osascript -e 'tell app "System Events" to display dialog "Last connextion date : '$LAST_CONNEXION_DATE'" buttons {"Cancel", "Continue"} cancel button "Cancel" default button "Continue"'

6 Replies to “Add Bash variables to “osascript -e” command”

  1. Very good. In fact…
    osascript -e ‘display dialog “Last connextion date : ‘$LAST_CONNEXION_DATE'” buttons {“Cancel”, “Continue”} cancel button “Cancel” default button “Continue”‘
    …is sufficient.

Leave a Reply

Your email address will not be published.

*