Getting Two Applications to Run in Sequence

For reasons that are unimportant here, I’m trying to get two applications to run in sequence. I initially started with the following:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

on run
	
	tell application "Mail" to activate
	
end run


on idle
	
	if application "Mail" is not running then
		
		
		quit
		
	end if
	
end idle


on quit
	
	tell application "Thunderbird" to activate
	
	continue quit
	
end quit

This worked, Mail would open, I could do what I needed to do, then I would quit Mail. Thunderbird would activate (could see the little black dot under the Thunderbird icon in the dock, but no window on the screen).

I then tried modifying the script to this:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

on run
	
	tell application "Mail" to activate
	
end run

on idle
	
	if application "Mail" is not running then
		
		quit
		
	end if
	
end idle


on quit
	
	tell application "Thunderbird" to activate
	
	tell application "Finder"
		activate
		set visible to true
		activate
	end tell
	
	continue quit
	
end quit

This only made matters worse. Mail would activate, when I quit Mail nothing happened. If I then started Thunderbird manually, and then quit, it would then activate again, seemingly from the running script.

Any help would be appreciated.

Homer712. I don’t have Thunderbird, so I tested with Safari, and your first script worked as expected. I changed the rate at which the idle handler was called from the 30-second default to 5 seconds to avoid the long delay after quitting Mail.

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

on run
	tell application "Mail" to activate
end run

on idle
	if application "Mail" is not running then quit
	return 5 --  the rate (in seconds) at which the idle handler is called
end idle

on quit
	tell application "Safari" to activate
	continue quit
end quit

-- this file saved as an AppleScript application with the stay-open option enabled. 

Given the above, it seems that the tell Thunderbird statement in your first script needs to be changed to open a window, but I can’t advise how this can be done. Do I not understand your request?

Thank you peavine, I have been banging my head against the wall all afternoon trying to figure out the correct sequence. I just changed Safari to Thunderbird in your script and it works perfectly, and Thunderbird opens in a normal window.

Just so you know why I was trying to come up with this script. Thunderbird (which you may know is an email client) has one incredible feature that in all it’s wisdom Apple left out of Mail. I have three systems, a MacBook Pro, an iMac and a Mac mini. With Thunderbird’s ability to designate where the “local folders” are kept (or in Apple’s Mail it’s called "On My Mac), mine are kept up on iCloud, so no matter which system I’m on, all my local folders appear in Thunderbird.

But, unlike Apple’s Mail program, Thunderbird has a very poor spam filtering process. Apple’s Mail is much, much better at catching spam. So, every morning, the first email run is done with Mail, all the spam gets filtered out and deleted, and then I’m back to work with Thunderbird.

1 Like