此answer提及如何启动1Password mini并从AppleScript中选择密码。作为后续行动,如何将密码内容复制到剪贴板?苹果中的命令应该是什么?
答案 0 :(得分:1)
1Password Mini似乎没有API,所以我们必须克服它。
这是一种方法:
set theSearchTerm to "facebook"
-- Search for the password in 1Password
do shell script "open x-onepassword-helper://search/" & theSearchTerm
delay 0.5
-- Copy to clipboard
tell application "System Events" to keystroke "c" using {shift down, command down}
delay 0.5
-- Ensure password is copied as pasteable text
do shell script "pbpaste | pbcopy"
-- Use the password
set thePassword to (the clipboard as text)
有几个问题需要注意:
"pbpaste | pbcopy"
行,文本将在90秒后自动删除。 (如果没有这一步,我就无法让我的脚本工作)这是一种处理1Password不返回任何搜索结果的不同方法。由于似乎没有任何方法可以解析1Password搜索结果(我很想知道是否有人有办法做到这一点),我已经实施了第二个kludge:检查剪贴板以查看是否它已被修改。如果没有搜索结果,剪贴板内容将不会更改。如果有搜索结果,则剪贴板内容会有所不同,假设您不能反复使用相同的密码!
set theSearchTerm to "foo"
set thePassword to ""
-- Search for the password in 1Password
open location "x-onepassword-helper://search/" & theSearchTerm
delay 0.5
tell application "System Events" to tell process "1Password mini"
set theClipboardTextPre to (the clipboard as text)
-- Copy to clipboard
keystroke "c" using {shift down, command down}
delay 0.5
-- Ensure password is copied as pasteable text
do shell script "pbpaste | pbcopy"
-- Check to see if clipboard contents have changed
-- If no change, it implies 1Password didn't return a search result
set theClipboardTextPost to (the clipboard as text)
if theClipboardTextPre is not equal to theClipboardTextPost then
set thePassword to theClipboardTextPost
end if
end tell
log thePassword
这里的缺点是,如果你有两个使用相同密码的网站,脚本会认为1Password没有返回搜索结果。