AppleScript: Press Enter Every X minutes If Terminal is Open and Application Has Been Idle for X Minutes

Solution 1:

Why not fix it in the terminal?

I would suggest something like

while true;
  do <whatever your terminal actions is>;
  sleep 60; #sleep 60 seconds
done;

This will go in a continuos loop. When the program exits, it jumps to sleep 60. Which will cause it to sleep for 60 seconds and then jump back to the execution part.

Although this is not specifically what you asked for, this might be an easier way to deal with it.

A bit closer to what you are suggesting:

 for i in {1..52};
   do <your action>;
   sleep 840;
 done

Solution 2:

Save this as a stay open application:

on idle
    if application "Terminal" is running then
        tell application "Terminal" to set currentTab to do script "" in front window
    end if
    return (14 * minutes)
end idle

Solution 3:

What problem are you trying to solve?

For instance, that's a common behavior of an SSH client, and is more easily, and better, solved by adding ServerAliveInterval 60 to your ssh config.