/ progress.applescript
progress.applescript
 1  on opened theObject
 2  	-- we are starting up the first time
 3  	call method "registerDefaultObjects:forKeys:" with parameters {{"Macintosh HD:Applications:freenet:", "Macintosh HD:Applications:entropy:", "Macintosh HD:Applications:samizdat:"}, {"location", "entropy", "samizdat"}}
 4  	try
 5  		--freenet status
 6  		set theResult to do shell script "ps -ax | grep  freenet" as string
 7  		if theResult contains "freenet.node.main" then
 8  			tell progress indicator "progress" of window "main" to start
 9  		else
10  			tell progress indicator "progress" of window "main" to stop
11  			
12  		end if
13  		--entropy status
14  		set theResult to do shell script "ps -ax | grep  entropy" as string
15  		if theResult contains "./entropy" then
16  			tell progress indicator "eprogress" of window "main" to start
17  		else
18  			tell progress indicator "eprogress" of window "main" to stop
19  			
20  		end if
21  		--samizdat status
22  		set theResult to do shell script "ps -ax | grep  samizdat" as string
23  		if theResult contains "./samizdat" then
24  			tell progress indicator "sprogress" of window "main" to start
25  		else
26  			tell progress indicator "sprogress" of window "main" to stop
27  			
28  		end if
29  	on error
30  		display dialog "Gadzooks! I couldn't find 'ps'!!!"
31  	end try
32  	
33  end opened
34  
35  on became main theObject
36  	-- we are unhiding. This is to prevent someone from canceling freenet via the terminal
37  	try
38  		--freenet status
39  		
40  		set theResult to do shell script "ps -ax | grep  freenet" as string
41  		if theResult contains "freenet.node.main" then
42  			tell progress indicator "progress" of window "main" to start
43  		else
44  			tell progress indicator "progress" of window "main" to stop
45  			
46  		end if
47  		--entropy status
48  		set theResult to do shell script "ps -ax | grep  entropy" as string
49  		if theResult contains "./entropy" then
50  			tell progress indicator "eprogress" of window "main" to start
51  		else
52  			tell progress indicator "eprogress" of window "main" to stop
53  			
54  		end if
55  		--samizdat status
56  		set theResult to do shell script "ps -ax | grep  samizdat" as string
57  		if theResult contains "./samizdat" then
58  			tell progress indicator "sprogress" of window "main" to start
59  		else
60  			tell progress indicator "sprogress" of window "main" to stop
61  			
62  		end if
63  	on error
64  		display dialog "Gadzooks! I couldn't find 'ps'!!!"
65  	end try
66  	
67  end became main
68  
69  on resigned main theObject
70  	-- if we are hiding, let's turn off the indicators to save cpu cycles
71  	tell progress indicator "progress" of window "main" to stop
72  	tell progress indicator "eprogress" of window "main" to stop
73  	tell progress indicator "sprogress" of window "main" to stop
74  end resigned main