Apple Logo Itsamac Hosting
Mac OS Journal
EditorialsColumnsFeaturesReviewsArchives/StaffSubscribe
 
Table of Contents From the Desktop Connect Feature Column The CoXFiles The Gaming Landscape Warehouse The Surf Report Simply Web The AppleScript Foundry
Mac Mastery Review - Office 2001 Review - Entourage 2001 Review - Word 2001 Review - Excel 2001 Review - PowerPoint 2001 Review - Jeopardy! Review - Snapz Pro 2 vs Screen Catcher Behind the Scenes  
   
 
Itsamac.com
Red Light Runner
Applelust.com
     
 

The AppleScript Foundry
March 2001 || Volume 01, Issue 08

Supporting Multiple Users

One of the more useful (but not perfect) changes in Mac OS 9 was the addition of support for multiple users. This is a feature that Windows has had for a long time, and it was long overdue for the Mac OS. Now you can have several users on a single machine, each with their own preferences and desktop settings, their own file storage area, etc. They can even customize the Apple Menu to their own taste, adding and removing aliases to programs, and documents they use frequently or not at all.

One of the reasons that this new arrangement is less than perfect is because older programs (even Applescripts) don't know about the addition of the Users folder on the startup drive, much less the other, more specialized folders within each user's folder. Most programs look for those folders in the System folder, where they always used to reside, and still do, for the owner account.

As anyone who has used a Mac prior to OS 9 knows, the System folder contains the Apple Menu Items folder, the Preferences folder, and other, more arcane stuff. And if you do not enable the Multiple Users control panel, those folders continue to function the way they always have.

Down the Garden Path...

But the folks at Apple realized a long time ago that not all of us leave our hard drives named "Macintosh HD" or use the same disk to startup each time. For that reason, they built into Applescript's Standard Additions dictionary the path to statement. For certain, key folders you can get the complete path to the folder by referencing it like this:

set my_path to (path to the system folder)

What you get back is an alias to that contains the entire path to that object. Remember, In Applescript, an alias is a pointer to a file or folder, not the actual item itself.

The complete list of supported paths (as of OS 9) is:

apple menu
application support
control panels
control strip modules
desktop
desktop pictures folder
extensions
Folder Action scripts
fonts
help
launcher items folder
modem scripts
plugins
preferences
printer descriptions
printer drivers
printmonitor
scripts folder
scripting additions
shared libraries
shutdown
speakable items
trash
startup
startup disk
system folder
temporary items
voices
keychain folder
current user folder
users folder
system preferences

Those of us who have been writing programs to run on Apple computers (both the old Apple //'s and the Mac) know that Apple has always advocated and supported indirection to allow "wedging" things into the OS when it was necessary. Smart programmers have used the indirect method of referring to things rather than going directly to the hardware (or the disk structure) to prevent one program from stepping on another.

Example: If you patched the old Apple // keyboard input routine, you left the address to your routine at a known (published by Apple) address to allow other programs to continue functioning as if you had never patched the original routine. Without this indirect method, other programs would have gone directly to the hardware or the original input routine, bypassing your patch, effectively "cutting you out of the loop."

The path to statement serves much the same purpose. If your scripts always access the items listed above using it, then you will always find the object you are looking for, no matter where it gets moved to in future releases of the OS. With the addition of Multiple Users and the dawn of OS X, this is becoming more and more important! While your mega-kewl script that does whatever may work on your Mac (whose hard drive is called "My big, fat, hard drive") with a hard-coded path embedded in it, it will break the moment you distribute it to someone else, and your script (and your reputation) falls flat on its face.

Follow Me!

OK, so we have established that the path to statement is important. Here's an example of what you can do with it:

If you save this script as a compiled script, you can stick it in your OSA Menu in the Finder Scripts folder, and you can add items to the Apple Menu by selecting them and invoking the script.

If you save this script as a classic applet, you can drop it in your "Speakable Items" folder and use it with Speech Recognition.

And the bonus is that this script will work with Multiple Users turned on! Any user, from the owner on down can use this script and it will work for them, without you having to explicitly name a path! You can even give this script to your friends, publish it on your web site, and it will work for anyone!

Another Example

If you have ever tried troubleshooting startup conflicts on your Mac, you know that items in the Startup Items folder launching every time you restart can be a pain. Rather than digging through the System folder or the Users folder looking for the offending items, why not put Applescript to work and let it disable them? Here's the script:

Except for the path to statement, there really isn't anything new in these scripts. But boy, are they helpful!

I will leave it as an exercise for the reader to write other useful scripts, but here are some suggestions:

  • Put Alias in Startup Items
  • Put Alias in Shutdown Items
  • Put Alias on Desktop
  • Disable Shutdown Items
  • Remove Items from Trash

And here's an extra challenge: Write a script to get the user's folder names from the Users folder and give the owner account an Applescript that puts an alias in each user's Apple Menu (or on their Desktop, or their Startup Items, etc.)! User management made easy!

In closing, here are some useful scripts from Apple. There are scripts here to add prefixes and suffixes to file and folder names, lock and unlock files, set file type or creator codes, some QuickTime scripts, some OS X Beta scripts, etc. Most of them require some version of OS 8 or higher.

More About the AppleScript Foundry

Every month in the AppleScript Foundry, I'll be sharing what I know about scripting. Since the object of this column is to get people who are new to scripting up and running, I will take a hands on approach, explaining new terms along the way. However, it is not my goal to talk down to the reader - If you want harder stuff, just write me! You can reach me at kevin@macosjournal.com or you can use the handy web feedback form.

Here is a list of places you can go to get more info on AppleScript:

Kevin's Icon Kevin Bradley - kevin@macosjournal.com
Kevin's Page - Feedback Form

back Mac OS Journal forward
 
 
   
© 2000 - 2004, MacOSJournal.com. All rights reserved. No part of this publication may be reproduced in any way without prior, expressed permission from the Publisher. It is the sole property of MacOSJournal.com and its writers, who retain copyright to their own works. If you wish to link to us, please see our Privacy Statement for conditions. Apple, Macintosh, and Mac are trademarks of Apple Computer, Inc, with whom we are in no way affiliated or endorsed.
Hosting provided by itsamac.com -- Macintosh Powered Web Hosting
Serve Different