mo-fu note

研究からキックボクシングまで何でも書いていきます!

AppleScriptでアプリケーションを起動してフォームにパスワードを入力する

MacのKeychainにパスワードを登録

security add-generic-password -a kurotaky -w password -s service-name

これでKeychainにパスワードを登録できる。パスワードを読み出すときはsecurity find-generic-password にする。 使い方は man security (security -- Command line interface to keychains and Security framework) で確認。

スクリプト

tell application "アプリケーション名"
    activate
    tell application "System Events"
        tell application process "TextEdit"
            delay 6.0
            set keyChain to do shell script "security find-generic-password -a kurotaky -s app-name -w"
            keystroke keyChain
            keystroke return
        end tell
    end tell
end tell

こんな感じでMacBook開いたときに選んだアプリケーションを起動して、フォームにMacのKeychainから読み取ったパスワードを入力できたりする。 Macで仕事している人はAppleScriptをいじると、アプリケーションを画面上に好きな配置にできたりして便利そう。