You can do this using AppleScript :
1. Open AppleScript Editor
2. Paste following code:
property appName : "Mail"
property minSecsBetweenLaunches : 600 -- seconds
property checkEvery : 5 -- seconds
-- DO NOT MODIFY AFTER THIS LINE IF NOT SURE --
property lastSeenOpen : ""
property lastMailState : ""
on run
idle
end run
on idle
my check()
return checkEvery -- check every n seconds
end idle
on check()
tell application "Finder" to set processes_names to name of processes
if (lastMailState is "") then
-- First run
set lastMailState to (processes_names contains appName)
if lastMailState then
set lastSeenOpen to current date
end if
else
if (processes_names contains appName) then
if (lastMailState is false) then
-- App just started
set lastMailState to true
if (lastSeenOpen is not "") then
-- Already been launched, check if launch allowed
set timeLeft to minSecsBetweenLaunches - ((current date) - lastSeenOpen)
if (timeLeft > 0) then
tell application appName to quit
activate
display dialog "Wait " & timeLeft & " sec. before opening " & appName & " again."
end if
end if
end if
set lastSeenOpen to current date
else
if (lastMailState is true) then
-- App just quit
set lastMailState to false
end if
end if
end if
end check
3. Adjust settings
The 3 first lines of the script can be edited to fit your needs. By default, check every 5 seconds if Mail has not been seen open since 10 min (which is 600 seconds).
4. Create the app
File menu > Export
- Choose app name & destination
- select to export as Application
- check "stay open..."
5. Hide from dock
In the Finder, find the app you just exported, then right-click on it, and select "Show package content". Then open "Info.plist" of the "Contents" folder in TextEdit, and, before the last </dict> of the file, paste:
<key>LSBackgroundOnly</key>
<string>1</string>
For info, after edit, end of my file looks like :
[...]
<string>event log</string>
</dict>
<key>LSBackgroundOnly</key>
<string>1</string>
</dict>
</plist>
And save it of course.
6. Set your app as startup item
System Preferences > Users > ...