Connecting Jotform with Keyboard Maestro

Hi, I'm looking for ways to pass the output of Jotform (a form builder that integrates with a variety of services) which is information a user submits to a form to a macro on Keyboard Maestro. I wanted to do the most direct way possible and avoid the need for additional tools like IFTTT if possible. A limited solution I have come up with was to have Jotform email me the user input and then have a rule in Mail app to run an applescript that passes the contents of that email to a Keyboard Maestro variable, deletes the email and activates a Keyboard Maestro macro. This works and I attached the AppleScript below in case someone is searching for this solution in the future but I don't love this method in part because the Mail app is a little glitchy for me. I'm wondering if there are any alternatives?

tell application "Mail"
set theAccount to account "(MailAccount)"
set theMailbox to mailbox "INBOX" of theAccount
set theMessage to ""
set allMessages to messages of theMailbox
repeat with i from (count of allMessages) to 1 by -1
set currentMessage to item i of allMessages
if subject of currentMessage is "(EmailSubject)" then
set theMessage to content of currentMessage
delete currentMessage
exit repeat
end if
end repeat
end tell

tell application "Keyboard Maestro Engine"
setvariable "(KeyboardMaestroVariable)" to theMessage
end tell

I've never used Jotform, but it sounds like you're trying to collect data entered by others onto a form you've created? If that's the case, I hate to ask an obvious question, but it seems important to figuring out how to answer your question: If it's not email, how else can you get the data from this form?

This doesn't seem to be a case where you can use a Javascript for Automation to pull data from the browser, because your users aren't on your Mac in your browser :). So what are the options you have to get the data the user submits?

-rob.

When you post code here you need to precede and follow it with a line of three backticks

```

Code here

```

so that others can read it without imposition of prohibitive levels of effort:

tell application "Mail"
    set theAccount to account "(MailAccount)"
    set theMailbox to mailbox "INBOX" of theAccount
    set theMessage to ""
    set allMessages to messages of theMailbox
    repeat with i from (count of allMessages) to 1 by -1
        set currentMessage to item i of allMessages
        if subject of currentMessage is "(EmailSubject)" then
            set theMessage to content of currentMessage
            delete currentMessage
            exit repeat
        end if
    end repeat
end tell

tell application "Keyboard Maestro Engine"
    setvariable "(KeyboardMaestroVariable)" to theMessage
    do script "(MacroName)"
end tell

Optionally, for code highlighting, you can follow the first three backticks with the name of a computer language:

```applescript

code here

```
1 Like

You should be able to improve on this by having a rule triggered when the email from Jotform comes in which runs the AppleScript directly, and only, on that email. No need to search the mailbox, no need to delete the mail (although you can move/delete it as part of the mail rule), etc. It'll reduce the "glitchiness" if you remove the unnecessary work.

1 Like

Thank you both. Fixed the applescript and it is more reliable now. Here's the updated version:

using terms from application "Mail"
	on perform mail action with messages matchmsgs for rule mailrule
		tell application "Mail"
			set msgcontent to (content of item 1 of matchmsgs)
			delete item 1 of matchmsgs
		end tell
		tell application "Keyboard Maestro Engine"
			setvariable "(KeyboardMaestroVariable)" to msgcontent
			do script "(KeyboardMaestroMacro)"
		end tell
	end perform mail action with messages
end using terms from