Apple Scripting Woes

rtellis
New Contributor

Hello.

At one of our locations we are currently using at least 10 Applescripts to manage workflow processes. At issue here is that these scripts routinely breakdown and/or fail and must be either restarted or nursed back to running. To further complicate matters; we have a mac environment trying to work with a windows environment with these scripts. Admittedly; no one on staff really knows anything about Apple Scripting and it has been suggested that we can convert some of these processes to Powershell. Is there anyone out there that has any experience with 1. Writing and maintaining Apple Scripts and 2. Converting these to a supported platform since Apple has pretty much washed their hands of them years ago?

Please advise;

Thanks

6 REPLIES 6

cdev
Contributor III

AppleScript isn't dead, but its uses are limited in certain respect. For the majority of cases, most admins are using either Python or Unix shell (sh/bash/zsh) scripts to handle configuration and workflow processes. The community here can certainly lend a hand with ideas or existing scripts that can fulfill a myriad of tasks depending on the goals and what your existing AppleScripts are working to accomplish.

A couple of solid resources:
Scripting OS X – great resource on shell, with some swift, plist, and profile info as well
macOS Automation – some older information, but great starting tutorials
MacScripter – community of folks using AppleScript and sharing snippets

mscottblake
Valued Contributor

Additionally, you will have more luck in this community if you pick a script that you need to modernize and ask specific questions about it.

chadlawson
Contributor

I am a big fan of all things automation including AppleScript and Automator. My preference (whenever possible) is to use shell or python instead. The only reason I resort to AppleScript is for interprocess automation/communication or to provide a user interface[1].

Apple isn't writing it off, in fact AppleScript is still being baked into all the modern apps. The problem is that Apple's walking the security/usability line well on the security side and apps and Applescripts need to be approved to get things done. And for that reason, other developers aren't putting in the hooks like they used to. Granted, I'd rather know that a script can't just do stuff on my machine without my knowledge/permission, but it makes my automation a little harder.

But I was just looking at the "Open Dictionary" menu item to get a piece of documentation and surprised at the number of modern/recent apps I had that provided AppleScript support.

The resources provided by @cdev is a great starting point. All three of those are in my Evernote as go-to reading when I need it. But like @mscottblake said, if you can provide us with either a sample script or describe what it does, we might be able to find a python/shell tool that can do the same thing but better.

  1. Python has the ability to create UI interfaces, too, but it's beyond my current knowledge whereas I already know how to do it with AppleScript.

timlarsen
Contributor

If you're primarily using AppleScript to invoke UI elements such as dialog boxes or more complex interfaces with menus, checkboxes, etc. there are some great alternatives out there. Many of us used to utilize the infamous cocoadialog tool (https://cocoadialog.com) which was fairly extensive as an easier to use replacement for AppleScript UI, however newer versions of macOS are not supported (due to the 32-bit runtime), and while we wait for the new version to be stable/released, a similar open source solution (that I've began using to replace cocoadialog) is something called Pashua (https://www.bluem.net/en/projects/pashua/). Of course for more basic dialog boxes, you can also check out Jamf's built-in JamfHelper tool or even the extremely simple one-line command jamf displayMessage -message [type your message here].

While all of the above solutions require some degree of shell scripting knowledge, much of what you need to know can easily be googled or found here on communities like Jamf Nation or the Macadmins Slack channel. While I used to use AppleScript fairly extensively myself, I found it was difficult to debug, error-prone and difficult to integrate into Jamf SelfService. Then again, every use case is different.

gabester
Contributor III

If you're serious about migrating the scripts out of Applescript and there is a lot of Windows interaction going on, you may want to look at installing powershell on macOS...

chadlawson
Contributor

Many thanks to @timlarsen for reminding me that CocoaDialog was still a thing and in development. I used to really like Pashua, so I'm going to have to take another look and see why I stopped using it. My main issue with both Pashua and CocoaDialog is that it becomes one more thing I have to deploy to get the work done.

Having said that, I'm trying to become fluent in Python and it has a couple good libraries for UI elements.