Answers:
对于10.6 Snow Leopard,可以使用Automator轻松添加服务,然后使用“系统偏好设置”分配任何键盘快捷键。看到快速用户切换/ Apple菜单?有关详细信息。
如果您使用的是CLI,则可以设置以下别名以快速切换:
alias switch='/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend'
我不仅可以使用BetterTouchTool进行更多操作,而且,它允许您执行的操作之一是“显示登录屏幕”(与注销并留在登录屏幕上不同)。长时间放置机器时,我会一直使用它来锁定我的机器……这是屏幕截图:
严格地说,Command+ Option+ Q 将记录你出去(与“你确定”的提示)。
但是我看不到有任何方法可以通过键盘触发快速的用户切换。现在,您可以编写一个AppleScript脚本,可以将其与按键关联。例如,看到这对实现细节。
set thePassword to "password"
set N to name of (info for (path to me))
set AppleScript's text item delimiters to (".")
set N to first text item of N
set AppleScript's text item delimiters to ""
set N to do shell script "/usr/bin/id -u " & N
do shell script "/System/Library/CoreServices/Menu\\ Extras/User.menu/Contents/Resources/CGSession -switchToUserID " & N
tell application "System Events"
tell process "SecurityAgent" to set value of text field 1 of group 1 of window 1 to thePassword
click button 2 of window 1 of application process "SecurityAgent"
end tell
根据Apple支持讨论中的Király的说法,他说这种组合有效:
...这可以通过Automator和Spark完成:
打开Automator,选择“运行Shell脚本”,然后粘贴其中(全部一行):
/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend
文件->另存为...->选择“另存为应用程序”,然后将该应用程序保存在方便的位置。然后使用Spark分配键盘快捷方式以打开该应用程序。
我使用Automator和Spark切换到登录窗口,然后在按Control-F13时使Mac进入睡眠状态...
Spark是一个功能强大且简单的快捷方式管理器。使用Spark,您可以创建热键来启动应用程序和文档,执行AppleScript,命令iTunes等。您还可以导出和导入热键库,或将其保存为HTML格式以进行打印。Spark是免费的,因此请适度使用!
这样做的方式略有不同,并增加了安全性(或视您的观点而感到烦恼),它是
为此,您需要在“系统偏好设置”应用程序中调整以下设置:
Exposé & Spaces
中的Exposé
标签下,设置您的Active Screen Corners
来Start Screen Saver
。Security
在General
选项卡,选中的选项Require password ... after sleep or screen saver begins
(你可能想选择immediately
从下拉列表)。您必须在每个帐户上执行后者(不幸的是,这没有全局设置)。
然后,您可以将鼠标移到屏幕的相应角落以锁定计算机(通过启动屏幕保护程序)。当有人按下键/移动鼠标时,将提示他们登录并可以从那里切换用户。
要切换到特定用户,我调用了一个在hints.macworld.com 文章的注释中找到的脚本。我在使用它时遇到了问题,因此我对其进行了调整,以使其工作。密码存储在钥匙串中,因此您不必担心以明文形式存储登录密码。你可以在这里找到要点。
--This script MUST be named "Switch to User.scpt", where User is the name of the user to switch to.
--You must first make a password item (a.k.a. a key) for the other user's password using Keychain Access, and call it "", where "user" is the other user's name and with the description "User Login". The script assumes that you make this key in your login.keychain, which is the default one.
--The first time you run this script, you will be prompted to allow Keychain Scripting to access the password of the key.
--This script requires "Enable access for assistive devices" to be enabled in the Universal Access system preference pane.
set username to word -1 of my findReplace(".scpt", "", (path to me as text))
-- Invoke Fast User Switching. The `id -ur username` part gets the uid number that corresponds to the username and substitutes it at the end of the CGSession command
do shell script "/System/Library/CoreServices/'Menu Extras'/User.menu/Contents/Resources/CGSession -switchToUserID `id -ur " & username & "`"
-- Use universal access to enter the text and to click the button
tell application "System Events"
repeat
if (do shell script "stat -f %Su /dev/console") is username then exit repeat
-- Get the password for the username
try
set pswd to (do shell script "security find-generic-password -g -s \"" & username & "\" -D \"User Login\" 2>&1 1>/dev/null | sed -e 's/password: \"//' -e 's/\"//'")
on error
exit repeat
end try
if exists window 1 of application process "SecurityAgent" then
tell process "SecurityAgent" to set value of text field 1 of window 1 to pswd
key code 36
exit repeat
else
tell application "SecurityAgent" to quit
do shell script "/System/Library/CoreServices/'Menu Extras'/User.menu/Contents/Resources/CGSession -switchToUserID `id -ur " & username & "`"
end if
end repeat
end tell
on findReplace(findText, replaceText, sourceText)
set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to findText
set sourceText to text items of sourceText
set AppleScript's text item delimiters to replaceText
set sourceText to sourceText as text
set AppleScript's text item delimiters to ASTID
return sourceText
end findReplace
要仅调用登录屏幕,我还有另一个脚本。你可以在这里找到要点
do shell script "'/System/Library/CoreServices/Menu Extras/User.menu/Contents/Resources/CGSession' -suspend"
这两个脚本都在我的quicksilver目录中。用户帐户之间的切换仅需几秒钟。