使用 AppleScript 粘贴密码
嘿伙计们。 在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从安全角度来看,最好将密码存储在登录钥匙串中,并在需要时从那里检索它。 (这样,您必须登录才能使用密码。如果您只是将密码保存在 applescript 中,则有权访问 applescript 文件的任何人都可以访问该密码。)
请尝试以下操作:
代码:
积分:
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:
The code:
Credits:
告诉应用程序“系统事件”按键“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.)