gpt4 book ai didi

golang exec osascript 不调用

转载 作者:IT王子 更新时间:2023-10-29 02:32:24 28 4
gpt4 key购买 nike

我写了一个发送文本的命令,但它不起作用,即使我将命令粘贴到其中也是如此。是否有语法错误或我遗漏了什么?

打印的命令是:/usr/bin/osascript -e '告诉应用程序“消息”' -e '将 mybuddy 设置为对文本聊天 ID“iMessage;+;chatXXXXXXXXXX”的引用' -e '将“测试”发送到 mybuddy' -e '结束告诉'

我的代码是:

command := fmt.Sprintf("/usr/bin/osascript -e 'tell application \"Messages\"' -e 'set mybuddy to a reference to text chat id \"%s\"' -e 'send \"%s\" to mybuddy' -e 'end tell'", chatid, message)
fmt.Println(command)
exec.Command(command).Run()

最佳答案

来自Command documentation :

The returned Cmd's Args field is constructed from the command name followed by the elements of arg, so arg should not include the command name itself. For example, Command("echo", "hello"). Args[0] is always name, not the possibly resolved Path.

所以,你应该这样做:

argChatID := fmt.Sprintf(`'set mybuddy to a reference to text chat id "%s"'`, chatid)
argMessage := fmt.Sprintf(`'send "%s" to mybuddy'`, message)

exec.Command("/usr/bin/osascript", "-e", `'tell application "Messages"'`,
"-e", argChatID, "-e", argMessage, "-e", "'end tell'").Run()

关于golang exec osascript 不调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45248144/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com