2017-07-21 11 views
0

テキストを送信するコマンドを書きましたが、コマンドを貼り付けると機能しません。いくつかの構文エラーや欠けていることはありますか?golang exec osascript not calling

印刷コマンドは次のとおりです。 /usr/bin/osascript -e 'tell application "Messages"' -e 'set mybuddy to a reference to text chat id "iMessage;+;chatXXXXXXXXXX"' -e 'send "test" to mybuddy' -e 'end tell'

私のコードは次のとおりです。Command documentationから

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() 

答えて

3

返さCmdをのArgsのフィールドが続くコマンド名から構成され、 argの要素なので、argにはコマンド名自体を含めてはいけません。たとえば、Command( "echo"、 "hello")とします。 Args [0]は常に名前であり、解決された可能性のあるパスではありません。

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() 

だから、あなたのような何かを行う必要があります

関連する問題