Since you are piping the output of the pbpaste
command directly to say
command, then e.g. [[volm 0.35]]
would need to be a part of what's on the clipboard as e.g. [[volm 0.35]]
must precede the content of what was actually going to be said.
I'd try using the following in place of what you are using:
set howLoudAndWhatToSay to "[[volm 0.35]] \"" & (get the clipboard as string) & "\""
set this_say_Pid to do shell script "say " & howLoudAndWhatToSay & " > /dev/null 2>&1 & echo $!"
Update: If you want to stick with using pbpaste
, then this example command should work:
set this_say_Pid to (do shell script "echo \"[[volm 0.35]] $(LANG=en_US.UTF-8 pbpaste -Prefer txt)\" | say > /dev/null 2>&1 & echo $!")
Note the primary differences between the command within the do shell script "..."
command in your question and my answer.
echo \"[[volm 0.35]]
is added in front of LANG=...
and note the space after ]]
.
The LANG=en_US.UTF-8 pbpaste -Prefer txt
is now enclosed in $(...)
which is using Command Substitution to, in essence, concatenate what gets echoed to the pipe ahead of the say
command.
As well as a matching closing literal double-quote \"
, before the pipe to say
, to go with the one in echo \"[[volm 0.35]]
. It did work in limited testing without the use of the opening and closing double-quotes however it's probably better to encase it in the double-quotes to account for something the shell might try to unnecessarily expand.
That said, on my system using 0.35
for the value in [[volm 0.35]]
didn't work well in that is was difficult to perceive the difference in volume from my normal setting. However using 0.3
in [[volm 0.3]]
the difference was notable. (This is one of the reasons why I used "e.g. [[volm 0.35]]
" in my opening sentence.)
[[volm 0.35]]
belongs in the line of code that I provided. – rubik's sphere Mar 18 '17 at 08:12cat <(echo [[volm 0.35]] ) <(LANG=en_US.UTF-8 pbpaste -Prefer txt) | say
, as is, works okay in abash
shell, it doesn't work in ash
shell, which is what AppleScript uses. So I do not believe it has to do with escaping any part of that particular command. If you open Terminal, assuming it is the default shell,bash
, and typedsh
and press enter, then execute that same command, it errors out withsh: syntax error near unexpected token \
(', the same as in AppleScript. It looks like the
sh` shell doesn't like Process Substitution. – user3439894 Mar 18 '17 at 12:17bash -c
, e.g.set this_say_Pid to (do shell script "bash -c \"cat <(echo [[volm 0.35]] ) <(LANG=en_US.UTF-8 pbpaste -Prefer txt) | say > /dev/null 2>&1 & echo $!\"")
, to actually run it in abash
shell, thesay
command will then work properly but you will not get thepid
of thesay
command, which of course then defeats the purpose. Hopefully rubik's sphere can use what I've suggested in my answer if there isn't another way to do it along the lines of your suggestion. – user3439894 Mar 18 '17 at 12:18sh
shell was having with Process Substitution<(...)
and to offer a solution usingpbpaste
by using Command Substitution$(...)
instead, as shown in my updated answer, which still includes my original answer as that shows another way to accomplish the same thing, albeit two lines of code instead of one. :) – user3439894 Mar 18 '17 at 16:18