首页 > 解决方案 > 如何将一个“do shell script”的输出用于Applescript中的另一个

问题描述

我正在使用 Mail.app 规则 (MacOS Mojave),该规则通过使用“执行 shell 脚本”命令的 AppleScript 为所选电子邮件创建 TaskWarrior 任务。

创建任务是没有问题的,但我想对任务进行注释,这需要您使用 shell 脚本的输出 - 即“已创建任务 [编号]”。因为注释任务是以下 shell 脚本:task [number] annotate [您的注释,在我的例子中是指向电子邮件消息的链接]。

我以为我设法将“创建的任务 [编号]”结果从第一个 shell 脚本转换为“任务 [编号]”,这是第二个 shell 脚本的开头,但现在结果是没有指定命令 - 假设'信息'。

我尝试使用延迟 1,以便一个 shell 脚本等待另一个完成,但无济于事。

这是具体的脚本:

tell application "Mail"
    set selectedMessages to selection
    set theMessage to item 1 of selectedMessages
    set messageid to message id of theMessage
    -- Make URL (must use URL-encoded values for "<" and ">")
    set urlText to "message://" & "%3c" & messageid & "%3e"
    set onderwerp to subject of theMessage
    set DueDate to display dialog "Wat is de due date?" default answer "friday"
    do shell script "/usr/local/bin/task add Email over " & onderwerp & " beantwoorden due:" & (text returned of DueDate) & " project:Work +email"
    -- This all works as it should. A task is created with the email subject and a due date that I give it. However, from here something goes wrong
    set task to the result
    set laatste to rich text 1 thru -2 of task
    set annotate to rich text 9 thru -1 of laatste
    do shell script "/usr/local/bin/" & annotate & " annotate" & urlText
end tell

我预计输出将是任务 [number] 用消息的 urlText 进行注释。但我得到:

错误“邮件出现错误:未指定命令 - 假设为‘信息’。没有匹配项。” 1号

标签: applescript

解决方案


未指定命令 - 假设为“信息”。

问问自己为什么 TaskWarrior 看不到命令​​是“注释”。这是因为您的第二个命令语法错误。改变

& " annotate" &

& " annotate " &

注意空间。


推荐阅读