Syntax
tell app "File Sharing"
(* find out about the first user connected to your machine *)
name of connected user 1
end tell
Dictionary commands
- close reference to object
You can close a File Sharing window used to set or alter the
privileges for a user or group:
close user "Guest"
This window can be opened from the Users & Groups tab by
selecting the username and clicking the Open button (AppleScript
cannot open this window, however).
- delete
reference to object
You can delete a user or group:
delete user "temp"
You should not allow important network script commands like
delete or make to fall into
the wrong hands.
- duplicate list
You
can create a new user or group with the same privileges as another
user or group with duplicate. The following
example duplicates a user and gives the new user a name:
tell application "File Sharing"
activate
set nw_user to duplicate user "iMarc"
set name of nw_user to "iMarc2"
end tell
- make
This command makes a new user, but the with data
parameter that is identified in its dictionary does not work.
- new user or group
You can make either a new user or group; you cannot make a new shared
item.
- with data anything
Alas, this parameter does not work properly with making new users or
groups in AppleScript 1.4, but I include it anyway because it appears
in the File Sharing dictionary. The next example shows user- and
group-creating code that does work:
tell application "File Sharing"
activate
set group_name to "graphics"
set user_name to "Van Gogh"
(* make the group first *)
set n_group to make new group
set name of n_group to group_name
(* make the user *)
set n_user to make new user
set name of n_user to user_name
set can connect of user user_name to true
set can change password of user user_name to true
set can do program linking of user user_name to false
(* add the new user to the new group *)
add user user_name to group group_name
end tell
- disconnect list of connected users
You should be able to use this command to disconnect a specified
user, but under Mac OS 9 none of the following commands have worked
properly:
disconnect {connected user 1}, disconnect connected user 1,
disconnect connected user "iMac," disconnect (connected user whose id =
131082}
Well, you get the picture. I am in search of a workaround or solution
to the disconnect command.
- show privileges of list of shared item objects
On my computer, the File Sharing control panel exposes just two
shared items to AppleScript; both are disks. Neither shared item
responds without an error to the show privileges
of command, as in:
show privileges of (shared item 1)
- add
reference to object
You can add a user to a group with this
command.
- to reference to object
This labeled parameter involves the keyword to
followed by a reference to a group:
add user "new_user" to group "new_group"
- remove
reference to object
You can remove a user from a group with this command:
remove user "defunct" from group "graphics"
- from reference to object
Follow the from label with a reference to a group:
remove user "defunct" from group "graphics"
Dictionary classes
- application
This class represents the File Sharing control panel. It has two
elements that represent the users who are connected to your computer
and the shared items on the machine, such as hard disks. You get
access to File Sharing by targeting the app in the
tell statement, as in:
tell app "File Sharing" to get connected
users
The following are application elements:
- connected user
The connected user object represents a user who is
connected to your machine via File Sharing. See the
connected user class later in this chapter for a
description of its properties.
- shared item
A shared item is an element such as a disk that
can be shared via File Sharing. The only property that can be
accessed with your script is its name. For
example:
tell app "File Sharing" to get name of shared item
2
The following are application properties:
- frontmost (boolean; read-only)
This is true/false value indicating whether File
Sharing is the desktop's active application (i.e.,
its windows are highlighted):
tell app "File Sharing" to get frontmost
- name (international text; read-only)
The name property returns "File
Sharing."
- version (international text; read-only)
The version property returns a value such as
"9.0."
- file sharing (boolean)
If File Sharing is turned off on your computer (i.e., network users
cannot get access to your disks and folders), then this property
returns false; otherwise true.
- sharing starting up (boolean; read-only)
When you turn File Sharing on, the app can take several seconds to
complete the task. If File Sharing is not undergoing its startup
routine, then this property is false.
- program linking (boolean)
If a user has program-linking privileges (which are set in the Users
& Groups tabbed panel of File Sharing), then she can execute
applications that reside on your machine. The program is actually
executed on her connected machine, even though its binary executable
code resides on your machine. The program-linking user cannot open
applications that are already open on your machine, however. For
example, if user "Gill" does not
have Photoshop 5 on her machine but you do, Gill can access this
program on her machine if that privilege is configured for her and
program linking is on. You can stop program linking from the File
Sharing control panel, as well as determine whether the users
connected over TCP/IP can use program linking. For instance, you can
stop program linking with script by setting this property to
false:
tell app "File Sharing" to set program linking to false
- owner name (international text)
This property returns the text from the Network Identity section of
File Sharing's Start/Stop tab. If the owner of File
Sharing privileges on your computer is called Admin, this property
returns "Admin."
- owner has password (boolean; read-only)
If the owner name identified in the File Sharing control panel has a
password then this property returns true.
- computer name (international text)
This property returns the computer name from the Network Identity
section of File Sharing's Start/Stop tab.
- connected user
This class represents a user that is connected to your machine via
File Sharing. The available properties are its
name, as in:
connected user "G4Power"
and its ID number. The code:
tell app "File Sharing" to get connected users
will return a list type, as in:
{connected user "G4Power" of application "File
Sharing"}
- name (international text; read-only)
This property returns the user's name as text, such
as "graphicsUser1."
- id (integer; read-only)
Every user has an id number of the form 65546.
- shared item
This class represents a item than can be shared via File Sharing,
such as a disk. Use the code:
shared items
to get a list of these resources, which looks
like:
{shared item "my2gig" of application "File Sharing",
shared item "Macintosh HD" of application "File
Sharing"}
- name (international text; read-only)
This command returns a shared-item name as text, such as
"my2gig."
- group
The group class represents a group-sharing entity
that can be created with File Sharing. The permissions can then be
configured for each group from the shared element's
Get Info window. For example, you might give the
"Graphics" group read-only
privileges on the disk "my2gig."
File Sharing groups can be referred to in AppleScript by their name,
as in group "Graphics." The code
tell app "File Sharing" to get groups
returns a list type with each one of the groups as
a member of the list. The multi-line code example earlier in this
chapter shows how you can make a new group.
- name (international text; read-only)
This property returns the name of the group as text.
- id (integer; read-only)
Every group is distinguished by an id number like 17.
- user
user objects represent the users that are
configured in your File Sharing control panel. They are distinguished
from connected-user objects, which are only created when a user has
actually connected to your computer. Users have names, IDs, and a few
other properties that can also be set in the File Sharing control
panel.
- name (international text; read-only)
This is the name of the user as text, as in
"graphicsUser1."
- id (integer; read-only)
Every user has an id number of the form 18.
- can connect (boolean)
If you do not want to allow a user to connect to your machine, set
this property to false:
set can connect of user "virusMan" to false
- can change password (boolean)
Set this property to true if you want to allow
users to dynamically change their passwords (they have to know the
original password to create a new one).
- can do program linking (boolean)
This property can be set to false if you do not
want to allow users to execute your applications.
- see entire disk (boolean; read-only)
Only the local File Sharing owner, who is also a user, can have this
property set to true. You can find out whether
they have this privilege with the following code:
set sed to see entire disk of user owner
name
The owner name property returns the local
owner's name as text, so they can be identified in
script code:
user owner name
Examples
(* make sure this variable can be accessed from anywhere in the script *)
global cu
tell application "File Sharing"
set cu to connected users -- returns a list of connected users
end tell
(* this subroutine writes user names to a file if there is at least one connected user *)
writeUsers( )
on writeUsers( ) -- subroutine definition
set ulength to (length of cu) -- number of connected users
if ulength is greater than 0 then
tell application "Finder"
activate
set tf to (make file with properties {name:"connected users", ¬
file type:"TEXT", container:desktop}) -- make this log file
set tf to tf as alias
end tell
open for access tf with write permission (* use osax from Standard
Additions *)
write ("Here are the connected users:" & return) to tf
repeat with n from 1 to ulength
write ((name of item n of cu) & return) to tf
end repeat
close access tf
else
display dialog "There are no connected users!"
end if
end writeUsers
|