Skip to main content
Solved

SetUp Script doesn't show notifications?


mkolb
Forum|alt.badge.img+8
  • Contributor
  • 33 replies

Hi everybody! Hope someone can help...

At the moment I'm working on a "First-Setup-Script" to perform some basic steps on a new Mac. This works, more or less, how it should. Except of the notifications. After every finished step, I want to show a small notification to inform the servicedesk member, who will set up the client, that this step has been done and the script itself is in progress.

To realise this, I use the following command

osascript -e 'display notification "ActiveDirectory join has been done" with title "ActiveDirectory - Done"'

When I use this command only to test it, it works without any problem. But running the script, this only leads to a lot of error messages and the notification never shows up.

So I tried to use jamf instead:

jamf displayMessage -message "ActiveDirectory join has been done."

This works, but as long as the servicedesk member not click on OK, the next message won't be shown. Seems like there can only one message window at the moment be displayed.

Maybe someone can help? Is there another, better way to inform about the progress? Or can you figure out, why the notifications work when I enter the command in the Terminal, but not when it comes from the script?

Thanks a lot for any help!

Best answer by mm2270

Yes, its likely the osascript (Applescript) portion that is the issue. If that is being run as root or by another account on the Mac other than the logged in user, its going to fail, because the OS often restricts Applescript interactions with the current console user, unless the command is run by or as the user. This is why it works if you just plug that line into Terminal, but doesn't work if its run by a jamf policy.

You could use the jamf displayMessage command, or look at using jamfHelper for these messages, which doesn't have the same problem. In either case, you'll probably want to push the command into the background with a & at the end so the script can continue, but then you'd need to shut each process down as it moves to the next item, and the next window.

Truthfully, although its more work up front, you may want to explore using a utility like cocoaDialog for this. Its better for something that requires text changing within the same window. The progressbar mode can do this fairly easily.
If you need some ideas on either of the above, post back and I can throw an example up, or just point to an existing one. There are plenty of them around.

View original
Did this topic help you find an answer to your question?

4 replies

mkolb
Forum|alt.badge.img+8
  • Author
  • Contributor
  • 33 replies
  • December 20, 2016

No ideas? :-(


mm2270
Forum|alt.badge.img+16
  • Legendary Contributor
  • 7880 replies
  • Answer
  • December 20, 2016

Yes, its likely the osascript (Applescript) portion that is the issue. If that is being run as root or by another account on the Mac other than the logged in user, its going to fail, because the OS often restricts Applescript interactions with the current console user, unless the command is run by or as the user. This is why it works if you just plug that line into Terminal, but doesn't work if its run by a jamf policy.

You could use the jamf displayMessage command, or look at using jamfHelper for these messages, which doesn't have the same problem. In either case, you'll probably want to push the command into the background with a & at the end so the script can continue, but then you'd need to shut each process down as it moves to the next item, and the next window.

Truthfully, although its more work up front, you may want to explore using a utility like cocoaDialog for this. Its better for something that requires text changing within the same window. The progressbar mode can do this fairly easily.
If you need some ideas on either of the above, post back and I can throw an example up, or just point to an existing one. There are plenty of them around.


Forum|alt.badge.img+16
  • Valued Contributor
  • 1002 replies
  • December 20, 2016

Definately use jamfHelper
Allows message over the top of other messages.
Allows message timeouts so they can automatically disappear after a certain amount of time.
Allows messages that don't require buttons.
Allows messages to be placed on different parts of the screen.


mkolb
Forum|alt.badge.img+8
  • Author
  • Contributor
  • 33 replies
  • December 21, 2016

Thanks! This was the direction I needed to be pointed at! :-)

The osascript part kind of worked when I used it that way:

#!/bin/sh

user=`stat -f%Su /dev/console`

sudo -u $user /usr/bin/osascript -e <<EndOfApplescript 'display notification "FileVault2 has been activated" with title "FileVault2 - Done"'
EndOfApplescript

For some reason sometimes it worked.. sometimes not. Don't know..

But jamfHelper did the job for me! Does exactly what I needed. Entered it this way:

/Library/Application Support/JAMF/bin/jamfhelper.app/Contents/MacOS/jamfHelper -windowType hud -title "FileVault2 - Done" -description "FileVault2 has been activated." -timeout 5

Thank you both very much!


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings