ScriptSpot

Forum topic · General Scripting

Exit the script from the pause mode after closing the external Photoshop application

By Any · 2020-08-29

Description

good day...

How to set an external event (CLOSE PHOTOSHOP) to exit script from PAUSE mode?

Comments (1)

.

jahman · 2020-08-29

'exit script from pause' sounds more like start some other script.

1. Get System.Diagnostics.Process instance of photoshop process
2. Make a callback that will be executed on Exited event
3. Subscribe this callback to this event using dotNet.addEventHandler


(
	calcs = (dotNetClass "system.diagnostics.process").getprocessesbyname "calc"
	
	if calcs.Count == 0 do
	(
		format "No running calcs found...\n" 
		format "Lets start one...\n" 
		ShellLaunch "calc" ""
		calcs = (dotNetClass "system.diagnostics.process").getprocessesbyname "calc"
	)
	
	fn StartThisAfterCalcClosed =
	(
		format "Finished...\n" 
	)

	fn OnCalculatorProcessClosed sender ev =
	(
		format "Calc just closed...\n" 
		
		StartThisAfterCalcClosed()
	)

	calcs[1].EnableRaisingEvents = true
	dotNet.addEventHandler calcs[1] "Exited" OnCalculatorProcessClosed
	dotNet.setLifetimeControl calcs[1] #dotNet
	
	format "Waiting for calc to close...\n" 
)