Show dialog at login (bash script)


The idea is that when somebody logs in to my Mac, a popup will show up and the date/time are written to a log.

I run the bash script from a cron job:

 @reboot ~/Develop/ 

(I know about launchd but choose to use cron, much easier)

the script:

osascript <<EOD
  tell application "System Events"
  display dialog "Unauthorized Login" buttons {"OK"} default button 1 with icon caution with title "WARNING!"
  end tell

echo "$(date) LogIn Alert" >> ~/Develop/login.log

I can execute the script with ./ All working well, the dialog is shown and login time is written to the log.

But when restarting my Mac the login date/time is written to the file (so the cron job is working), but the dialog is not popping up.

(I did look at the question Run AppleScript from bash script)

So my question is how to show this dialog when rebooting my Mac?
(macOS 10.12.3)

Best Answer

You should run your script above not as a cron job but as described in this post (*) :

Make sure not to confuse running things on the login screen and running things on user login like in the question below:

Still, there is no need for you to log user logins as they are automatically logged. See "man last" and "cat /var/log/authd.log".

(*) Relevant part of the linked post above - or use launchd, as described in the link

Select "Application"
click "Show library" in the toolbar (if hidden)
Add "Run shell script" (from the Actions/Utilities)
Copy&paste your script into the window
Test it
Save somewhere, for example you can make an "Applications" folder in your HOME (you will get an
Go to System Preferences -> Accounts -> Login items
Add this app