Great idea, Stan. Thank you!
Do you think there’s any reason one couldn’t use a Folder Action Script to do basically the same thing?
Also, oddly, I’ve noted that SOMETIMES speaking from the background account works. Bug or feature? Who knows?
What I’m using right now in the background script is this: do shell script “say \”some text to speak\” &>/dev/null &”
That stuff at the end is some voodoo I found somewhere that’s supposed to let the speech run without holding up script execution. But just to make sure, I wrapped it in an “ignoring application responses” block (belt & suspenders, for sure!)
Here's what I'd do to accomplish your task.
1. Create a folder accessible to both users, perhaps "/Users/Shared/SayMe/" or whatever.
2. Have the background process write the text to be spoken in timestamped text files in the "SayMe" folder. Timestamping (i.e. – "2014-10-03_16.49.35.txt") will allow them to be retrieved and spoken in order.
3. The foreground process would poll for text files, speak them, then delete them. Alternatively, you could archive the files or log the spoken text.
Below is some quick-and-dirty code you can use as a starting point for the foreground process, which would need to be saved as a stay-open script application.
HTH, Stan C.
on run idle end run
on idle set sayFolder to "/Users/Shared/SayMe/" try -- look for files to speak set filesToSay to paragraphs of (do shell script "ls " & sayFolder & "*.txt") on error errText number errNum if errText contains "No such file or directory" then set filesToSay to {} else -- unknown error, so throw it error errText number errNum end if end try -- speak and delete each file repeat with i from 1 to (count filesToSay) do shell script "say <" & item i of filesToSay do shell script "rm " & item i of filesToSay end repeat return 5 -- seconds until next poll end idle
|