AppleScript for System Admins WebCast
Justin Elliott writes "Watch Apple Computer's own AppleScript wizard, Sal Soghoian, present 'AppleScript For System Admins' during Mac OS X Labs' September 24 webcast. Learn about essential AppleScript tools and tips under Mac OS X. Discover how AppleScript can be used for administrative tasks, and how to use AppleScript to effectively interact with the Mac OS X file system."
Good point - I remember on one of the admin lists some guy obviously from an OS9 background was having problems moving files around with Apple Script. I introduced him to shell scripting - turns out he had about 30 lines of code to essentially do some basic file copying and moving. I showed him he could do the same thing in about 3 lines of shell script.
You have to be careful with shell scripts on the Mac filing system though - you can end up losing the resource forks which breaks some files.
AppleScript rocks. It's a great way for users (that's users, not geeks) to automate stuff on a Mac. Its biggest power is probably the english-like language.
Like this iChat AV example:
tell application "iChat"
send video invitation to account "John Doe"
end tell
You can download the webcast software, but will not be able to connect or see anything until 1 PM EDT next wednesday.
Where are the shell scripts?
What did you want to do from the shell? Some programs are designed to be used from a command line in the Unix way, others are happier being controlled via the GUI and OSA [which you can still get to from the shell using open(1) and osascript(1)]. Those commands won't completely eliminate Applescript, but they will let you stick mostly to sh and only bring in OSA where the target program demands it.
AppleScript is like Perl's forgotten twin brother: Perl is fast to write and impossible to read, and AppleScript is highly readable but impossible to keep "in your head" .. too much like a weird dialect of english.
.. for instance you can generate diagrams in OmniGraffle diagramming tool entirely through scripts! I was trying to create a script to generate ERD from MySQL schema but gave up after a while because AppleScript is so chewy.
That being said it *rocks* for controlling GUI apps
I wonder sometimes what Apple doesn't gradually dump AppleScript for Python? Think about it: it would give them a scripting platform as powerful as powerful as Java, but (nearly) as simple as AppleScript (perhaps more readable, and certainly more maintainable). Python 2.3 is going to get bundled with Panther, and is used in some core "essential functionality" in Panther and already has bindings to pretty much everything one would needs to tightly stitch to Apple's platform (ojbc, quartz, Java apps via JPE, etc).
luckily it is a week from now - which is longer than the whimsical 'just curious' attention span (I attribute) to most ./'ers
-shpoffo
I think when it comes to automating applications AppleScript is more powerful than people realize. However when it comes to system scripting, shell and perl scripts are still the way to go. I recently wrote a login script that I prototyped as a shell script and then wrote out as an AppleScript. I ended up using the shell script. Much smaller and easier to write. Simple commands like echo and grep take many, many lines of code in AppleScript. Even complicated tools like awk are still easier to write out than the equivalent AS code. As I become more familiar with perl and python, those might even be a better way to do system scripting.
You can manipulate files with resource forks in the shell using the MacCp, MacMv, and ditto commands which will preserve the resource forks.
You can call AppleScript from other scripting languages (Python/Perl/Bash, etc) and call other scripting languages from AppleScript, so you can do each manipulation in whatever language you find most convenient. I usually find it easiest if you keep AppleScript for manipulating objects within your application (Quark) and do the backend data manipulation in Perl etc.
Apple has a page about using 'do shell script' to invoke UNIX scripts from AppleScript
To go in the reverse direction, you invoke the AppleScript using