2017-07-21 3 views
0

Ich schrieb einen Befehl, der einen Text sendet, aber es funktioniert nicht, obwohl wenn ich den Befehl einfügen in es tut. Gibt es einen Syntaxfehler oder etwas, das ich vermisse?Golang exec osascript nicht aufrufen

Der gedruckte Befehl lautet: /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'

mein Code:

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

Antwort

3

Vom Command documentation:

Die zurück CMDs Args Feld vom Befehlsnamen gefolgt von der aufgebaut ist, elements of arg, also sollte arg nicht den Befehlsnamen selbst enthalten. Zum Beispiel Befehl ("echo", "hallo"). Args [0] ist immer Name, nicht der möglicherweise aufgelöste Pfad.

Also, sollten Sie so etwas wie:

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