【问题标题】:Applescript: How can I stop the script until the user puts in their password in Apple Mail?Applescript:如何在用户在 Apple Mail 中输入密码之前停止脚本?
【发布时间】:2011-12-14 18:53:38
【问题描述】:

由于 Apple Mail 中的一个错误,我的 applescript 在同步之前就被挂断了,如果 SMTP 服务器与描述不匹配,它将再次要求输入密码..所以用户必须输入他们的密码并点击确定或在任何事情发生之前进入。 我出现了一个对话框提示,上面写着“在钥匙串中记住密码是个好主意”,然后我在它上面激活了另一个提示,这样他们就无法在不输入密码的情况下点击确定……但这似乎不一致而且瘸。我宁愿想办法让提示不会出现,或者我可以暂停脚本直到输入密码。

--Activate Mail Application
tell application "Mail"
activate "Mail"
display dialog "Welcome to Mailbox setup with Google Mail. Please enter the password for your e-mail when prompted. This should not take any more than a minute."

delay 0.5

--Variables
--Creating account


set email_address to (short user name of (system info)) & "@EMAIL.com"
set full_name to (long user name of (system info))
set mailboxname to (long user name of (system info))
set shortname to (short user name of (system info))
set myPass to text returned of ¬
    (display dialog "Enter password for " & ¬
        quoted form of shortname ¬
        with title ¬
        "Gmail" with icon stop ¬
        default answer ¬
        "" buttons {"Continue…"} ¬
        default button 1 ¬
        giving up after 5 with hidden answer)


try
    set newacct to "imap.gmail.com"
    set newacct to make new imap account with properties {name:mailboxname, user name:email_address, password:myPass, uses ssl:true, server name:"imap.gmail.com", port:993, full name:full_name, email addresses:{email_address}}
    tell application "System Events" to key code 53

    --Create SMTP filter
    set addsmtp to "smtp.gmail.com"
    set addsmtp to make new smtp server with properties {server name:"smtp.gmail.com", user name:email_address, uses ssl:true, authentication:password, password:myPass}


    --Attach SMTP server
    set smtp server of newacct to addsmtp
    delay 1.0
    tell application "System Events" to tell process "Mail"
        set frontmost to true
        keystroke return
    end tell

    --Mailbox Sync
    delay 0.5
    on return
    tell application "Mail"
        synchronize with account mailboxname
    end tell

end try
end tell

Example

【问题讨论】:

    标签: applescript


    【解决方案1】:

    有一个解决方法:

    set authentication to ("axct" as constant)

    而不是这个

    set authentication to password
    

    【讨论】:

      【解决方案2】:

      您可以通过检查是否打开工作表(在您的情况下用于输入密码)来等待密码输入:

      tell application "System Events"
          tell process "Mail"
              repeat until exists sheet 1 of window 1
                  delay 0.1
              end repeat
          end tell
      end tell
      

      【讨论】:

        【解决方案3】:

        前几天我也开始了这方面的工作。 据我所知,你应该和我有同样的问题。 当您告诉脚本设置新的 SMTP 服务器时,您必须声明

        “身份验证:密码”

        问题是这只是一个错误。 如果您检查 AppleCode 中的 Mail 库,它会指出“authentication”是“password”后缀的正确前缀。

        尽管如此,它每次都会抛出错误。

        我目前看不到任何解决方法,以前尝试过的人也看不到。 主要是垃圾

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2018-03-27
          • 2020-05-04
          • 1970-01-01
          • 2015-01-30
          • 1970-01-01
          • 2015-12-03
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多