Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Mac OS X Leopard introduces a number of newly scriptable system preference panes, including:
Accounts, Appearance, CD & DVD, Desktop, Dock, Expose and Spaces, Network, and Security.
However, occasionally you may wish to launch the System Preferences application and switch to a
specific pane or tab for user review or interaction. Here are sample scripts for controlling the System
Preference application:
A script demonstrating how to open a specific system preference pane, how to get the names of
the anchors of a pane, and how to switch to a specified anchor (tab):
ACCOUNTS PREFERENCES
The scripting support in the Accounts Preferences is read-only, meaning you cannot use scripting to
generate new users. You can use scripting to set the image used as the current user's picture.
The accounts preferences are read-only except being able to change the picture of the current
user:
A script demonstrating how to add login items for the current user account:
APPEARANCE PREFERENCES
You can now script the look and functionality of basic user-interface controls.
A script demonstrating how to get and set the properties of inserted disks:
-- OPEN APPLICATION
set properties of video DVD to {insertion action:open application, custom
application:"/System/Lirabry/CoreServices/Front Row.app:"}
-- RUN A SCRIPT
set properties of picture CD to {insertion action:run a script, custom script:file "Mac OS
X:Users:sal:Library:Scripts:Import Photo CD.scpt"}
end tell
end tell
DESKTOP PREFERENCES
By manipulating the scriptable Desktop Preferences, you can control how images are used as desktop
backgrounds.
A script demonstrating how to set the desktop to display a folder of images in random sequence:
Although scripting support is not integrated into the Screen Saver preference, you can use scripting to
start the current Screen Saver:
-- LAUNCH SCREENSAVER
try
tell application id "com.apple.ScreenSaver.Engine" to launch
end try
DOCK PREFERENCES
You can use AppleScript to control the way the Dock appears in Mac OS X:
A script demonstrating how to get and set the properties of the Dock preferences.
A script demonstrating how to get and set the properties for Expose:
-- EXPOSE SHORTCUTS
get the properties of the all windows shortcut
-- {class:shortcut, mouse button:4, function key:F9, function key modifiers:{}, mouse button
modifiers:{}}
get the properties of the application windows shortcut
-- {class:shortcut, mouse button:0, function key:none, function key modifiers:{}, mouse button
modifiers:{}}
get the properties of the show desktop shortcut
-- {class:shortcut, mouse button:0, function key:F11, function key modifiers:{}, mouse button
modifiers:{}}
-- DASHBOARD SHORTCUT
get the properties of the dashboard shortcut
-- {class:shortcut, mouse button:0, function key:none, function key modifiers:{}, mouse button
modifiers:{}}
-- SETTING A SHORTCUT
set the properties of the application windows shortcut to {mouse button:3, function key:left control,
function key modifiers:{none}, mouse button modifiers:{command}}
end tell
end tell
-- LAUNCH EXPOSE
try
tell application id "com.apple.exposelauncher" to launch
end try
get properties
-- {spaces enabled:true, spaces rows:1, arrow key modifiers:«class
-- LAUNCH SPACES
try
tell application id "com.apple.spaceslauncher" to launch
end try
NETWORK PREFERENCES
Script the Network preferences is focused on getting and changing the current location setting:
A script demonstrating how to get network properties and the name of the installed set of
locations, and how to change the current location:
SECURITY PREFERENCES
Basic security preferences can now be read and set with scripts.
A script demonstrating how to get and set the basic computer security settings:
-- LAUNCH SPACES
try
tell application id "com.apple.spaceslauncher" to launch
end try
-- LAUNCH EXPOSE
try
tell application id "com.apple.exposelauncher" to launch
end try
-- LAUNCH DASHBOARD
try
tell application id "com.apple.dashboardlauncher" to launch
end try
-- LAUNCH SCREENSAVER
try
tell application id "com.apple.ScreenSaver.Engine" to launch
end try
The resulting XML of the newly created property list will look something like this: