使用AppleScript粘贴密码

MrS*_*ine 1 applescript paste

大家好.在Mac OSX 10.6上工作,我的"问题"是我希望在我的用户帐户上使用安全密码,但是不管是否需要在进程需要管理员权限时粘贴它就会遇到麻烦.

我使用Autopilot,并认为这是输入它的最佳方式,因此我可以使用直接的AppleScript输入,2使用带有"osascript ..."的shell脚本.3启动AppleScript编译的应用程序4使用自动驾驶仪中的文本扩展功能(在这种情况下似乎不起作用)

我到目前为止的脚本是:

    set the clipboard to "FooBar"
    set resultAnything to the clipboard as text
Run Code Online (Sandbox Code Playgroud)

当我在脚本编辑器中执行时,我的结果是"FooBar"但是我不能让它在其他任何地方工作.

我不能用

    set the clipboard to "FooBar"
    tell application "System Events"
    keystroke "v" using command down
    end tell
Run Code Online (Sandbox Code Playgroud)

因为密码对话框似乎没有接受命令+ v paste方法.

有帮助吗?顺便说一下,在发布这个问题之前,我确实在网上和stackoverflow上进行了搜索,所以如果我忽略了已经发布的内容,请原谅我.

谢谢

pft*_*221 10

安全方面,最好将密码存储在登录密钥链中,并在需要时从那里检索密码.(这样您必须登录才能使密码可用.如果您只是将密码保存在AppleScript中,那么任何有权访问applescript文件的人都可以访问该密码.)

请尝试以下方法:

  1. 打开钥匙串访问(/ Applications/Utilities)
  2. 选择登录钥匙串时,按窗口底部的"+"按钮
  3. 输入钥匙串项目名称,帐户名称和服务器密码.您将再次需要钥匙串项目名称.
  4. 制作一个包含以下代码的新Applescript,将myKeyname替换为Keychain Item Name
  5. 首次运行脚本时,请选择"始终允许"和"允许".这将允许Keychain Access在您登录时自动获取密码.

代码:

set keyName to "myKeyname" -- replace myKeyname with the Keychain Item Name from step 3
tell application "Keychain Scripting"
    tell keychain "login.keychain"
        set myPass to password of (some key whose name is keyName)
    end tell
end tell
tell application "System Events"
    keystroke myPass
end tell
Run Code Online (Sandbox Code Playgroud)

积分:

  • Keychain脚本代码来自anika123:http://hintsforums.macworld.com/showthread.php?t = 108626
  • 系统事件代码来自Lri在这个问题的第一个答案