Restart a program without interrupting frontmost app/window

I’m using FastScripts to set hotkeys for various scripts but every ten minutes or so FastScripts stops working properly. I wrote a script that restarts FastScripts every 10 minutes, but it interrupts whatever I’m doing by unselecting whatever window I’m working in. This despite trying to keep the current window on top using “get name of processes whose frontmost is true”.

So here’s the script (oh and btw I’m using TheTime variable in the place of delay b/c delay doesn’t seem to work in Yosemite when you save the script as an app).

on idle
	tell application "System Events"
		set theFrontmostApp to item 1 of (get name of processes whose frontmost is true)
	end tell
	tell application "FastScripts"
		quit
	end tell
	tell application theFrontmostApp
		activate
	end tell
	set TheTime to current date
	set NewTime to TheTime + (0.05 * minutes)
	repeat while (current date) is less than NewTime
		delay 0.5
	end repeat
	tell application "FastScripts"
		activate
	end tell
	tell application theFrontmostApp
		activate
	end tell
	return 600
end idle

Despite using “tell application theFrontmostApp to activate” once the script finishes in unselects whatever app I’m working in.

Any ideas?

I’d be more concerned with tracking down why FastScripts is having problems – I find it rock-solid.

One thing that could be causing problems in your script is that the name of a process is not necessarily the name you use in a tell application statement. You have the process name – try telling sSystem Events to set frontmost of that process to true.

FastScripts was working great until I started using it with ASObjC & scripts that call script-bundles. I haven’t really had a chance to trouble-shoot it so I don’t know for sure.

Make sure you let Daniel Jakult know. I suspect he’d be interested in some samples.

It seems like the problem is mostly likely in my sloppy script. If it persists after tightening things up, I’ll let him know.