【问题标题】:how do you force apple script + aws vault to wait for mfa access你如何强制苹果脚本 + aws vault 等待 mfa 访问
【发布时间】:2021-07-23 00:22:30
【问题描述】:

我有一个这样的苹果脚本

#!/bin/zsh

tell application "iTerm"
    activate
    select first window

    # Create new tab
    tell current window
        create tab with default profile
    end tell

    # Split pane
    tell current session of current window
        split vertically with default profile
        split vertically with default profile
        split vertically  with default profile
    end tell

    # Exec commands
    tell first session of current tab of current window
        write text "aws-vault exec my-role -d 12h --no-session"
        write text "start him"
    end tell
    tell second session of current tab of current window
        write text "start her"
    end tell
    tell third session of current tab of current window
        write text "start you"
    end tell
    tell fourth session of current tab of current window
        write text "start me"
    end tell
end tell

问题是脚本没有等待我从 aws 命令填写 mfa 信息。我也尝试过aws-command; start him,但它只是退出并且根本不执行start him。有人遇到过这种情况吗?

【问题讨论】:

    标签: bash terminal iterm2 osascript


    【解决方案1】:

    我认为这不太可能,因为 Apple Script 无法知道 aws 命令需要 mfa 信息以及您是否已完成输入该信息。

    但是有 2 种非常老套的方法可以实现这一点:

    使用delay

    此选项可能非常不可靠,但它可能会完成工作。 您可以使用delay 命令让AppleScript 等待X 秒,直到它运行write text "start him"。假设您需要大约 10 秒来输入 mfa 信息,然后您将使用 delay 10。下面是代码的样子。

    # more code above...
        tell first session of current tab of current window
            write text "aws-vault exec my-role -d 12h --no-session"
            delay 10    # <-- change this value to your liking
            write text "start him"
        end tell
    # more code below...
    

    使用display dialog

    我个人认为这可能是您最可靠的选择。您可以做的是打开一个对话框,输入 mfa 信息后,单击“确定”以恢复脚本。所以你会有这样的东西:

    # more code above...
        tell first session of current tab of current window
            write text "aws-vault exec my-role -d 12h --no-session"
            display dialog "Click Ok once you are done "
            write text "start him"
        end tell
    # more code below...
    

    只是一个小警告:我没有测试上述代码,因为我没有 macOS 计算机。

    【讨论】:

    • 啊不幸的是这不起作用,显示对话框暂停所有脚本并且不允许我输入 mfa 信息
    • @sf8193 很不幸。 delay 方法有效吗?
    • 它做到了!我会继续并标记为已回答
    猜你喜欢
    • 1970-01-01
    • 2019-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-14
    • 1970-01-01
    相关资源
    最近更新 更多