Section 13.3. Running Superuser Commands


13.3. Running Superuser Commands

In the world of Mac OS X, there are three kinds of people: standard account holders, administrators, and superusers. The kind of account you have determines what kind of changes you can make to your Mac (Table 13-1).

Table 13-1. Different kinds of accounts and the powers they wield

Type of account

Can change account-specific preferences

Can change other accounts' preferences

Can open and delete other people's files

Can open and delete system files

Standard

Yes

No

No

No

Administrator

Yes

Yes

Yes

No

Superuser

Yes

Yes

Yes

Yes


In a fresh installation of Mac OS X, the first account you create is automatically an administrator account. From then on, you can create additional accounts (either standard or administrator) by opening System Preferences Accounts and clicking the lower-left + button.

Say you wanted to edit some files in the System Library CoreServices folder, where Mac OS X stores all its private settings and programs. Naturally, if you were a standard or administrator account holder, the files there would be off-limits. However, by posing as a superuser, you can convince Mac OS X to let you modify those system files.

Since the chown Unix program transfers control of a folder from Mac OS X to you, your first instinct would probably be to write an AppleScript like this:

do shell script "chown user /System/Library/CoreServices/"

Replace user with your own user name. Otherwise, Mac OS X will try to transfer ownership of the folder to a nonexistent account on your Macunless, of course, you happen to have an account named user.

In essence, that single-line script tells Mac OS X, "Run the chown program, and tell it to transfer ownership of the System Library CoreServices folder to me." Unfortunately, you'll encounter a roadblock when you run the script, as described in Figure 13-4.

The solution? Add with administrator privileges to the end of your command:

do shell script "chown user /System/Library/CoreServices/" ¬     with administrator privileges

Now, rather than seeing an error message when you run your script, you see a password dialog box, as shown in Figure 13-5.

Once you enter your password, your script successfully runs chown, making you the new owner of the CoreServices folder. Be careful what you do with your newfound powers, though; if you feel like deleting a system program (say, the Finder), nothing will stop you now.

If this folder-mangling power becomes too overwhelming for you, you can reverse the effects of your previous script by running this one:

do shell script "chown root /System/Library/CoreServices"

with administrator privileges. The term root describes Mac OS X itself. Therefore, when you run this script (and enter your administrator password), you surrender control of System Library CoreServices back to Mac OS X.

Figure 13-4. Since you're not a superuser, Unix politely rejects your request to transfer ownership of the CoreServices folder. By posing as a superuser, however, you can eliminate this complaint.


Figure 13-5. Enter your administrator password, and your Unix command proceeds with superuser powers.




AppleScript. The Missing Manual
AppleScript: The Missing Manual
ISBN: 0596008503
EAN: 2147483647
Year: 2003
Pages: 150

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net