使用 AppleScript 粘贴密码

发布于 2024-11-08 19:31:01 字数 720 浏览 4 评论 0原文

嘿伙计们。 在 Mac OSX 10.6 上工作, 我的“问题”是,我希望在我的用户帐户上有一个安全的密码,但讨厌每当进程需要管理员权限时就必须粘贴它的麻烦。

我使用 Autopilot,认为这是输入此信息的最佳方式,所以我可以 1 使用直接的applescript输入, 2 使用带有“osascript...”的 shell 脚本 3 启动一个applescript编译的应用程序 4 使用 Autopilot 中的文本扩展功能(在这种情况下似乎不起作用)

到目前为止我拥有的脚本是:

    set the clipboard to "FooBar"
    set resultAnything to the clipboard as text

当我在脚本编辑器中执行时,我的结果是“FooBar” 但我无法让它在其他地方工作。

我无法使用

    set the clipboard to "FooBar"
    tell application "System Events"
    keystroke "v" using command down
    end tell

因为密码对话框似乎不接受command+v粘贴方法。

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

谢谢

Hey guys.
Working on Mac OSX 10.6,
My "problem" is that I would like a secure password on my user account, but hate the trouble of having to paste it in whenever a process needs admin privileges.

I use Autopilot, and figure it's the best way to input this, so i can
1 use straight applescript to input,
2 use a shell script with "osascript..."
3 launch an applescript compiled application
4 use the text expansion facility in Autopilot (doesn't seem to work in this case)

The script that I have so far is:

    set the clipboard to "FooBar"
    set resultAnything to the clipboard as text

When I execute in script editor my result is "FooBar"
But I can't get it to work anywhere else.

I can't use

    set the clipboard to "FooBar"
    tell application "System Events"
    keystroke "v" using command down
    end tell

Because the password dialogue doesn't seem to accept the command+v paste method.

Any help?
By the way I did scour the net and stackoverflow before posting this question, so forgive me if I overlooked anything already posted.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风蛊 2024-11-15 19:31:01

从安全角度来看,最好将密码存储在登录钥匙串中,并在需要时从那里检索它。 (这样,您必须登录才能使用密码。如果您只是将密码保存在 applescript 中,则有权访问 applescript 文件的任何人都可以访问该密码。)

请尝试以下操作:

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

代码:

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

积分:

Security-wise it's probably better to store your password in the login keychain and retrieve it from there when you need it. (That way you must be logged-in for the password to be available. If you just keep the password in an applescript, it is accessible to anyone who has access to the applescript file.)

Try the following:

  1. Open Keychain Access (/Applications/Utilities)
  2. Press the '+' button at the bottom of the window while the login keychain is selected
  3. Enter a Keychain Item Name, Account Name and your server Password. You will need the Keychain Item Name again.
  4. Make a new Applescript containing the following code, replacing myKeyname with the Keychain Item Name
  5. Select 'Always Allow' and 'Allow' when you first run the script. This will allow Keychain Access to get the password automatically when you are logged in.

The code:

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

Credits:

与他有关 2024-11-15 19:31:01

告诉应用程序“系统事件”按键“securepassword”应该可以工作,至少如果密码是字母数字的话。 (并且您在按住修饰键时不会调用脚本。)

tell app "System Events" to keystroke "securepassword" should work, at least if the pasword is alphanumeric. (And you're not invoking the script while holding modifier keys.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文