I’m calling a ruby script after AppleScript is setting the clipboard to a value. incoming mail sets the clipboard to the Subject of an email. That works.
Then I call a ruby script which does some magic with that email subject and sends it to the database.
do shell script "/Users/rich/.rbenv/shims/ruby /Users/rich/myscripts/Misc/incoming_alpha.rb"
It doesn’t complete. If I take that very line out and insert it into a new script, it works when I run it manually. So I can run the script that the Rules point out, and it works fine with the selected subject. But that last line doesn’t trip, and I do not know why.
Am I missing something here? How can I get this to work?
If you’re using clipboard, it may simply need a delay before the ruby script to insure it doesn’t run the Ruby before the clipboard contains the new value. I don’t know, but if the clipboard set and the Ruby bot work independently but not combined, that’s the first thing that comes to mind.
Try something like “delay .2” before calling the Ruby.
So I had to move the do shell script line into the iterator for the Mail Rules handler:
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
tell application "Mail"
repeat with theMessage in theMessages
set emailSubject to the subject of theMessage
set the clipboard to emailSubject
end repeat
[b]do shell script "/Users/rich/.rbenv/shims/ruby /Users/rich/AB_scripts/abc_incoming.rb"[/b]
end tell
end perform mail action with messages
end using terms from
I wasn’t sure how this block behaved. I had all the extra work outside below this block, which never got achieved. Apparently that rule calls the block as a handler, and not the whole script.