Safari applescript, triggering new application help

I just joined this forum
I need a simple applescript…I’m new to applescript so I’m not sure how to make it
I know though that I need an “on run” and “end run”
What I want is when I open safari, I want the script to see that and then open another app for me
Does anyone have a script that does that?
Any help would be appreciated
Thanks

So posting here was a first for you, huh?
Well one “first” deserves another: I’m going to post a reply - instead of a query. I’m the one here always asking asking asking…hopefully my first attempt at giving back will lad you to victory. So there’s a couple ways to do what you want.

I might need more details into what you REALLY want to have happen here. But one answer to your post is quite simple:

tell application "Safari"
	activate
end tell

--substitute "Your Application Here" for "Quicktime Player" below

tell application "QuickTime Player"
	activate
end tell

You save this as an application. You could even overlay this new “application’s” icon with the Safari icon, place it in your dock and every time you click it to launch Safari, it’s “partner” app would come along with it.

Again, don’t know if that’s what you’re really after here. The above is not very elegant. But certainly fits the criteria that you laid out in your initial post.

Furthermore you could save this applescript as an application and save it with the option to “Stay Open”. The issue here is that it’s going to poll your system every single 10 seconds. As soon as it detects that Safari is up & running, it will launch your partner app. Looks like this:

on idle
	set idleInterval to 10 -- seconds between checks
	set targetApp to "Safari"
	
	tell application "System Events"
		set processExists to exists process targetApp
	end tell
	
	if processExists is true then
		
		tell application "QuickTime Player"
			activate
		end tell
		
		tell application "System Events"
			set frontmost of process "Quicktime Player" to true
		end tell
		
		set idleInterval to 10
		
	end if
	
	return idleInterval
end idle

Either of these will do the job of launching “Your Application” once Safari is launched.

so wait do I press run whenever I want to use it?
Thanks for the script though…I’m just not sure what to do next…how to use it

Oh and one more thing I forgot to ask
When you said “you can use either of these”, where’s the splitting point between the two scripts

Yes, you could just push run but there’s a more convenient way to launch it. There are mulitple formats in which you can save AppleScripts. One of those is to save it as an “Application”. (File → Save As → beside ‘File Format’ select “application”.

After doing this, you merely click on the newly created “Application” icon itself to run the script it contains. So doing this requires fewer steps than finding the script, opening the script, running the script then closing the script.

Save it as an application, double-click to launch it. Done. So again, you could put this “Application” in your Dock, even attach the familiar Safari Icon - or whatever icon you wish to it. Then click it in the dock and presto.

The first script is the simplest, mos straight forward. If it does what you need: Launch Safari AND some other app then use it and call it done. The other one is going to constantly poll your system (every 10 seconds) to “see” if Safari is running then it will launch the other app. I like the former concept, one that is NOT polling the sytem all the time. So if that initial script works OK for you then I’d stick with it.

Hmm ok well I don’t see it running
Sorry I just am still a little unclear:/
So this is the first script

on idle
set idleInterval to 10 – seconds between checks
set targetApp to “Safari”

tell application "System Events"
	set processExists to exists process targetApp
end tell

if processExists is true then
	
	tell application "QuickTime Player"
		activate
	end tell

and this is the second

tell application “System Events”
set frontmost of process “Quicktime Player” to true
end tell

	set idleInterval to 10
	
end if

return idleInterval

end idle

Am I correct in saying that?

Sort of. But these aren’t individual scripts. The “two” scripts you have above are really ONE script. So take out where you said, “and this is the second” and put both “halves” into one script. Then save the entire thing as a stand-alone app.

BTW, what app do you want to open up along-side Safari?

PS: One other crucial note: If you’re going to go this route then you have to also check the “Stay Open” box when you do your save as. Otherwise, it’s going to launch and IMMEDIATELY quit again.

Hi,

One thing new applescripters try to do is run idle handlers in the Script Editor. You could post a script that runs in the Script Editor with a repeat loop and a delay with unix sleep command. After the op sees how it works, you then modify it where it uses an idle handler. Here’s an example with Stickies and beep.


repeat
	tell application "System Events"
		set safari_exists to exists process "Stickies"
	end tell
	if safari_exists then
		beep 1
	end if
	do shell script "sleep 1"
end repeat

Press Command + “.” to make the script stop running.

gl,

Thank you KevinCBrock and Kel
KevinCBrock, the script you made now works
I forgot to do it where it says “Stay Open” box when you do your save as.
That made it work
The program I’m having it open is called TimeOut!
And one thing…it keeps switching to Time Out!
If I change the interval, it will do it less often, right?

In other words, can I get it where it checks at launch for Time Out! but doesn’t switch to that app every 10 seconds

Yeah…I was afraid of that. Why not try this then:



tell application "Safari"
	activate
end tell

tell application "Time Out!"
	activate
end tell

Save as application and attach Safari Icon to it

Ok well that works then
Thanks everyone for your help