Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos 如何使用applescript从1Password复制密码内容?_Macos_Applescript - Fatal编程技术网

Macos 如何使用applescript从1Password复制密码内容?

Macos 如何使用applescript从1Password复制密码内容?,macos,applescript,Macos,Applescript,本文介绍了如何启动1Password mini并从applescript中选择密码。作为跟进,如何将密码内容复制到剪贴板?applescript中的命令应该是什么 1 Password Mini似乎没有API,因此我们必须在整个过程中摸索 这里有一种方法: set theSearchTerm to "facebook" -- Search for the password in 1Password do shell script "open x-onepassword-helper://sea

本文介绍了如何启动1Password mini并从applescript中选择密码。作为跟进,如何将密码内容复制到剪贴板?applescript中的命令应该是什么

1 Password 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秒后不会自动删除。(没有此步骤,我无法使脚本正常工作)
  • 如果搜索词未返回任何结果,则会出现AppleScript错误
  • 这里有一种不同的方法,用于处理1个不返回任何搜索结果的password。由于似乎没有任何方法来解析1密码搜索结果(我很想知道是否有人有办法做到这一点),因此我实现了第二个难题:检查剪贴板,看看它是否已被修改。如果没有搜索结果,剪贴板内容将不会更改。如果有搜索结果,剪贴板内容将不同,假设您不反复使用相同的密码

    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没有返回搜索结果。

    @Agilebbits\u Jasper既然您已经回答了链接问题,您还知道如何将CMD+C发送到1Password吗?非常感谢。