登录用户通过loginwindow应用程序在mac中

时间:2011-06-02 14:32:44

标签: macos login

我编写了一个程序,该程序会在loginwindow应用程序前弹出,并询问某些信息。一旦信息得到验证。可以看到登录窗口,您可以选择要登录的用户。 我想在我的应用程序中运行脚本/ bash代码或某些东西,以便用户没有机会看到loginwindow。相反,应用程序应该登录来宾用户本身。我尝试过使用applescript,即

set logInUser to "Guest"
set logInPassword to "Guest"

tell application "System Events"

    tell application process "loginwindow"

        key code 53

        delay 1

        key code 125
        delay 1
        key code 36 using option down
        delay 1
        keystroke tab
        delay 1
        key code 117
        delay 0.5
        keystroke tab
        delay 0.5
        key code 117
        keystroke return
        delay 1
        keystroke tab
        delay 0.2
        repeat with aChar in characters of logInUser
            keystroke aChar
            delay 0.2
        end repeat
        keystroke tab
        delay 0.5
        repeat with aChar in characters of logInPassword
            keystroke aChar
            delay 0.2
        end repeat
        key code 98 using control down
        delay 0.2
        keystroke return

    end tell
end tell

由于loginwindow没有响应这个AppleScript,我也尝试了bash,但没有任何工作。任何帮助都会很棒。 :(

1 个答案:

答案 0 :(得分:0)

了解你在这里真正要做的事情会很有用。在登录期间注入同步事件的受支持方式是authentication hook。这比尝试“在LoginWindow前面运行”要强大得多。中断loginwindow的问题在于您需要处理注销和快速用户切换的情况。您还可以使用loginwindow的LoginHook在登录完成之前运行脚本。但同样,这些都是在用户输入凭据之后(在LoginHook的情况下,它是在验证凭据之后)。

也就是说,在LoginWindow之前放置内容的最佳位置是在SystemStarter中创建一个旧式/Library/StartupItems守护进程。它们在loginwindow之前同步运行,但仅在初始启动期间(不是在注销后或在FUS期间)。