Shell/Applescript help needed

jhuls
Contributor III

I have a policy that updates an application. The package provided by the developer will launch the application into the menubar under OS versions 10.10-10.12 but not for 10.9. I've attempted to write a script that would launch it under 10.9 with my own post install script. That failed miserably though so I was going for a simple prompt for the user to restart. I'm in the class of scripting of knowing enough to be dangerous but below is what I currently have. Some insight on what I'm doing wrong would be appreciated. If someone wants to assist with the preferable method of launching the software, that would be great. The launch service needing to be launched is the following...

/Library/LaunchAgents/com.alertus.AlertusDesktopClient.plist

#! /bin/sh

Major_OS_Version=$(sw_vers -productVersion | awk -F '.' '{print $1 "." $2}')

sudo /usr/local/jamf/bin/jamf recon

if [ $Major_OS_Version == "10.9" ]
    then
        osascript <<EOT
            tell application "Finder"
                activate
                display dialog "Update is complete. Your computer needs restarted for the process to be completed." buttons {"No Restart", "Restart"} default button "Restart" with icon caution
                if button returned of result is "Restart" then
                    restart
                end if
                end tell
            EOT`
fi

exit
3 REPLIES 3

mm2270
Legendary Contributor III

Hi @jhuls. So if I understand the issue(s) correctly, it's that a) you're having trouble getting the LaunchAgent to load for Macs on 10.9, and what the vendor supplied isn't working to do that, and b) your Applescript isn't displaying anything when run?

If I have that correct, I can tell you right off that the likely problem with the Applescript/shell script above is that you have a back tick (` ) mark after the last EOT, which is probably throwing the whole thing off. You don't want that there. Also, I might add, drop the sudo on the recon line. If the script is being run from a Jamf Pro policy or other process, there's no need for the sudo there.
One other recommendation, though this is just a nitpick and not really necessary, I would change the line getting the OS version to use cut. It's better suited for what you're after than awk is

Major_OS_Version=$(sw_vers -productVersion | cut -d. -f1,2)

But to back up all the way to the start, can you show us what you put together to load the LaunchAgent for your Mavericks systems that wasn't working? I'm willing to bet we can get that to work, although the method I'm thinking of was a bit spotty under 10.9.

jhuls
Contributor III

Thanks for the info!

As it turns out I took a second to try thinking a little more clearly over lunch and looked at an old version of the software which launched correctly under 10.9. I grabbed the line out of their post install script and, tada, I have the launching working now. The line they used was...

su -l $loggedInUser -c "/bin/launchctl load -F -S Aqua "/Library/LaunchAgents/com.alertus.AlertusDesktopClient.plist""

I'm still going to review what you wrote above so I can learn from it. One of these days maybe I'll get some solid time to learn a thing or two. For now I'm basically stealing code and slapping together whatever seems to make sense and asking for the occasional help when needed.

donmontalvo
Esteemed Contributor III

For 10.9 and older, we've been using this to launch as logged in user:

/bin/launchctl asuser `stat -f %u` open /usr/bin/open "/Applications/ApplicationName.app"
--
https://donmontalvo.com