We help top organizations stay competitive, by implementing the latest disruptive technologies.

Latest Posts
 

Deploying AppleScripts with LANDESK Management Suite

Deploying AppleScripts with LANDESK Management Suite

Recently I was on a call with a current LANDESK Management Suite customer and he was expressing his disappointment to me regarding LANDESK’s inability to support AppleScripts.

Imagine his surprise when I told him he could.

Now, the information the support team provided to this customer is “technically” correct, LANDESK Management Suite does not natively support direct AppleScript deployments.

However, with a very simple workaround you can take advantage of the power of all of your AppleScripts and use LANDESK to deploy them. And, the best part about the workaround, you don’t have to change the AppleScript at all. You simply need to put a shell script wrapper around it.

A couple of weeks back, I blogged about how you can update your the Exchange server in a client devices Outlook settings and in that blog, I used this very trick to wrap my AppleScript in a shell script to deploy it out with LANDESK.

Let’s walk through an example of how to create that wrapper.  Grab your AppleScript or use my simple example below that will set a desktop background.

tell application "System Events"
 tell every desktop
 set picture to "~/Pictures/IvantiScreen1.jpg"
 end tell
end tell

If you were to copy the text above into Apple’s ScriptEditor application and hit play, after having tweaked the “set picture path” to match a valid path on your machine, your desktop backgrounds will all update.

However, if you were to save the file and deploy it with LANDESK, it would fail.  This is where the workaround comes in.

Opening up a text editor, such as TextWrangler or Xcode, and create a new Shell script. For our workaround, we need to change the interpreter in the shebang line.  Typically, your shell script will have something similar to ‘#! /usr/bin/sh’.  Change it to:

#!/usr/bin/env osascript

That is all you have to do.  Now you can copy in your AppleScript, save the file as a .sh file, set the execute permissions on the file and deploy it as a standard package.

In my example script, I added an additional line to download the desired background image.  My entire script to set the desktop background is available below or can be downloaded from GitHub:

#!/usr/bin/env osascript

# setDesktopBackground
# Created by Bennett Norton on 1/25/17.

# you first need to download your background image you'll use
# call the directory you want to save the background image to
# set the download path to your image
do shell script "cd ~/Pictures && { curl -O http://bn-sgu-ldserver.ldlab.org/SoftwareDist/IvantiScreen1.jpg; cd -; }"

# run the applescript to set the desktop background
# make sure the paths match
# if you set the path to ~/Pictures above, then it should be ~/Pictures below
tell application "System Events"
 tell every desktop
 set picture to "~/Pictures/IvantiScreen1.jpg"
 end tell
end tell

If you’re new to LANDESK or scripting, the information below will assist you in setting the file permissions and creating the package.

To set the permissions, you need to open Terminal and run:

chmod +x /path/to/your/script.sh

With the script now ready for execution, zip it and copy it to your package share.  Once you’ve done that, build the LANDESK software package.

  • From the LANDESK Console, open Tools > Distribution > Distribution Packages
  • Inside the menu tree, highlight My Packages or Public Packages and then select the New Package button on the menubar and select New > Macintosh > Macintosh Agent
  • Give the package a name, description and point the primary file to the .sh file created previously
  • Fill out the Metadata details if desired
  • Save the package
3 Comments
  • Hyrum Bowers
    Posted at 18:03h, 04 April Reply

    Hey sir, so I have followed this with a popup window script. I can run the popup.sh through the terminal, but when running it from Ivanti it fails with a 16386 return code. I added permissions and moved it in a zip file, but I am not quite sure what else I can do to make it work.

    Here is my script.

    #!/usr/bin/env osascript
    set theDialogText to “Test Alert.
    Testin Progress.
    ” & (current date) & “.”
    display dialog theDialogText

    Any thoughts?

Post A Comment