reopen an open application

Hi,

How do you rerun an open application. I tried this:

on applicationShouldHandleReopen_hasVisibleWindows_(theApplication, aFlag)
        display dialog "reopen"
        run
        return YES -- edited: this didn't work
    end applicationShouldHandleReopen_hasVisibleWindows_

The app needs to remain running.

Editted: I should say open instead of running.

Thanks,
kel

Hi,

this handler is called when the user double-clicked the application in Finder or clicked the icon in the dock.

What exactly are you going to accomplish ?

Hi Stefan,

Just like the reopen handler in AppleScript, I want the application to rerun.

on run
– do something
end run

on reopen
run
end reopen

When you double click on the app or run it from the dock the app should do something. It has no windows.

Thanks,
kel

as AppleScriptObjC apps have no run handler, use something like


on applicationWillFinishLaunching_(aNotification)
	myRunHandler()
end applicationWillFinishLaunching_

on applicationShouldHandleReopen_hasVisibleWindows_(theApplication, aFlag)
	myRunHandler()
	return false -- as the app has no windows you can return false
end applicationShouldHandleReopen_hasVisibleWindows_

on myRunHandler()
	-- do something
end myRunHandler

Hi Stefan,

Can I call the applicationDidFinishLaunching method? Like this:

on applicationWillFinishLaunching_(aNotification)
	-- initilize
end applicationWillFinishLaunching_

on applicationShouldHandleReopen_hasVisibleWindows_(theApplication, aFlag)
	my applicationDidFinishLaunching_(aNotification) -- how to get aNotification?
	return false -- as the app has no windows you can return false
end applicationShouldHandleReopen_hasVisibleWindows_

on applicationDidFinishLaunching_(aNotification)
	-- do something
end applicationDidFinishLaunching_

I wanted to keep the main part of the script in the applicationDidFinishLaunching handler. I read in the Developer docs something about using that handler for the notification. But, if it can’t be done then, I can switch the main part of the script in my own handler.

Editted: forgot to change the handler name in the WillFinishLaunching.

Edited: no we don’t need that! :smiley: Sorry, I’m starting to rush.

Edited: Ok, now I got it right I hope.

Thanks,
kel

yes, you can call applicationDidFinishLaunching unless you’re considering the notification info.
Use missing value as parameter

Hi Stefan,

That sounds like it should work. Trying it.

Thanks a lot,
kel

Hello Stefan,

It seems to be working great now! :smiley: I’ll post the script template soon.

Thanks a lot,
kel