How to use the password from the keychain in a box running in Mail.app?

I am trying to configure applescript that performs (via python imaplib ...) certain manipulations with my gmail account (which is not configured using IMAP in Mail.app, only POP).

For this script, you must log in using my password. If not for security reasons, I could just hard-set my password in a python script ...

Is there a way that such a script called inside Mail.app (for example, by the rule) can use my password stored inside keychain?

+4
source share
3 answers

The following from the script is copied to my script library ...

- If you need to use a password in a script, you can use a keychain to store the password and get a script for it. Thus, your password is protected because you do not need to store passwords in clear text in a script.

- Create a password item - open the Keychain Access application and select the keychain in the left column. Then click File> Create Password Entry ..., enter a name, enter the account in the account and enter the password. Highlight it in the password list and get information about it. Under the Attributes button, enter its type as a shared key. This was chosen because there are few of them, and the search is much faster.

- NOTE. In 10.7 apple, keychain scripts are removed, and so we now use the security command line tool

getPW("name of keychain item") on getPW(keychainItemName) do shell script "security 2>&1 >/dev/null find-generic-password -gl " & quoted form of keychainItemName & " | awk '{print $2}'" return (text 2 thru -2 of result) end getPW 
+6
source

There is such a method, it is called Keychain Access Scripting, and Apple refuses it with OS X 10.7, discarding the necessary extension from AppleScript. However, you can use the security shell utility, for example, in detail on the TextMate blog (be sure to read the comments - there are several reasons for this), or, and Id recommend that you use a third-party replacement for the Apples component, Daniel Jalkuts perfectly Used key scripts * a > application. After installation, the following bit of AppleScript will retrieve your password (assuming the account name is "GMail"):

 tell application "Usable Keychain Scripting" to get password of first generic item of current keychain whose account is "GMail" 
+2
source

I use this

 # Replace %ACCOUNT_NAME% with account name of Keychain item get_pw () { security 2>&1 >/dev/null find-generic-password -ga "%ACCOUNT_NAME%" \ | sed 's/password: "\(.*\)"/\1/' } PASS=$(get_pw) 
0
source

Source: https://habr.com/ru/post/1412282/


All Articles