do shell script alpha.rb

Hi folks.

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?

Cheers

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.

Hi there. Ya tried delay 1 and it still isn’t running for some reason. So here is the current breakdown:

  • In the Mail.app, I select a received email, then choose Apply Rules. This triggers the proper script, and the clipboard is set accordingly.

  • In Script Editor, I manually run the script (Mail has a qualified email selected in background), and it works.

Somehow, the triggered rule won’t run the ruby script. The syntax is correct, the manual option works just fine.

Is there a restriction on Mail.app on running certain scripts? That’s where the restriction is, from what I gather.

Any ideas?

SOLVED

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.