A display message to a User.

Hello,


I would appreciate someone's help with with displaying a simple pop up/notification message to a user after a LaunchDaemon has succesfully run. It has to be a Launchdaemon and not a Launchagent.


I have the plist and script in place and its works great but I now need to be shown how to display a message to an end user.


thanks

MacBook Pro with Retina display, OS X Yosemite (10.10.3)

Posted on Sep 30, 2016 7:31 AM

Reply
24 replies

Oct 6, 2016 8:43 AM in response to infmac

infmac wrote:


It has to be a Launchdaemon and not a Launchagent.

Hello infmac,

Why is that? Launch Agents are meant to be run in a logged-in user context. Launch Daemons are run in any context but may not have the necessary connections to a user environment to interact with it. If it works with a Launch Daemon, it is only because you are getting lucky that day. It should be a Launch Agent. If, for some reason, it absolutely, positively must be a Launch Daemon, then you will need an additional Launch Agent to interact with the user.

Oct 6, 2016 8:49 AM in response to infmac

There was a small syntax omission in the osacript line. I made the following red text changes, and the dialog works on 10.11.6.


osascript <<-'EOF' &> /dev/null


The &> /dev/null is optional, and redirects the stdout/stderr message “button returned:OK, gave up:false” that is returned by the osascript dialog after the OK button is clicked, or it times out.

Oct 7, 2016 4:45 PM in response to infmac

As you are not running this from the Terminal, then the optional part of my previous post would not be pertinent to the script. It only serves to prevent one seeing the text returned from the display dialog, either when the user clicks it, or it executes its own giving up time out.


It looks like with Hiroto's additional help, you have this working now.

Oct 10, 2016 6:42 AM in response to VikingOSX

I have just tested this on version 10.12 i.e Sierra.


At the start of the script we have the lines:


if [[ $Version -ge 12 ]]

then

launchctl unload /Library/LaunchDaemons/net.sierra.plist

rm -f /Library/LaunchDaemons/net.sierra.plist

rm -f /usr/local/bin/sierra.sh

exit 0


which should unload the plist and delete the script IF the version is 12.


I can confirm that neither the plist or script deleted. Can someone perhaps help me as to why that would be?


thanks

Oct 10, 2016 1:03 PM in response to infmac

The script logic works fine on my macOS Sierra install. However, your original script had the following, which is missing in your above post.


Version=$(sw_vers | grep ProductVersion | tail -c 7 | cut -d . -f 2)


Without Version set, your conditional will always fail. The osascript will also fail because it is not yet syntactically correct.


You should remove one set of brackets in your if statement: if [ $version -ge 12 ].


You should update:


osascript <<'EOF'


to


osascript <<-'EOF'

Oct 11, 2016 2:57 AM in response to VikingOSX

Hi Viking,


I just hadn't included the line in my post but yes the script is showing as yours above above and it behaves the same way i.e on sierra it does not remove the plist and delete the script.


On a separate note I need to amend the script so that :

a) the "install macOS sierra.app" deletes upon download (so not having to wait for it to finish downloading)

b) it deletes the "install macOS sierra.app" IF it appears on the user's desktop so for example if a user copies it from a usb key to their desktop.


Many thanks again.


Here is the current script:


#!/bin/bash


Version=$(sw_vers | grep ProductVersion | tail -c 7 | cut -d . -f 2)


if [ $Version -ge 12 ]

then

launchctl unload /Library/LaunchDaemons/net.sierra.plist

rm -f /Library/LaunchDaemons/net.sierra.plist

rm -f /usr/local/bin/sierra.sh

exit 0

else

rm -rf /Applications/Install\ macOS\ Sierra.app/


# get uid who is running an instance of /System/Library/CoreServices/SystemUIServer.app/Contents/MacOS/SystemUIServer

uid=$(ps -ax -o uid,command | awk '/MacOS\/SystemUIServer/ {print $1}' | head -n1)


# if no such uid is found, exit

[[ -n $uid ]] || exit

# execute osascript by user of the uid

sudo -u "#$uid" osascript <<-'EOF'

tell application "System Events"

activate

display dialog "macOS Sierra is not allowed on computers at this time." with title "Technology Notice" buttons {"OK"} default button 1 giving up after 30

end tell

EOF

fi

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

A display message to a User.

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.