Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

thewatts

macrumors newbie
Original poster
May 18, 2009
1
0
so, writing a code to send me a text when a program [VisualHub] quits after converting video files.

the issue is that when i initially run the script, it follows through with running the second script called FilesDone [one which i made with automator].

the script is a repeating check to see if visualhub is present in the running applications. if so - keep checking. if not - then run [FilesDone], end repeat.

Code:
on run {input, parameters}
	
	repeat
		tell application "System Events"
			if ((get name of the processes) does not contain "VisualHub") then
				tell application "FilesDone"
					activate
					exit repeat
				end tell
			end if
		end tell
	end repeat
	
	
	return input
end run

VisualHub is running when i initially run the script. yet - it runs FilesDone anyway, but keeps checking to see if VisualHub is closed [and when closes - runs FilesDone again].

what have i missed that FilesDone is executed at the start of the repeat?

thanks,
 

neutrino23

macrumors 68000
Feb 14, 2003
1,881
391
SF Bay area
I'm not sure why this is happening.

I suggest putting in a display dialog statement to show you what is being returned.

Once you see what is being returned you can modify the test.

Suggestion: I'd add a small delay of a few seconds so you aren't hammering the system checking if the program is still running or not.

-- delay for n seconds
delay n
 

mysterytramp

macrumors 65816
Jul 17, 2008
1,334
4
Maryland
I suggest putting in a display dialog statement to show you what is being returned.

Definitely a good suggestion. A great deal of debugging gets done that way.

(BTW, you have proven that the process's name is "VisualHub" and a typo isn't just causing the issue? Just asking ...)

I'd also consider rewriting that if...then clause to make it positive and see if something shakes out, such as

Code:
if ((get name of the processes) contains "VisualHub") then
    -- nothing, maybe add a beep here. It'll drive you nuts but it works
    else
	tell application "FilesDone"
		activate
		exit repeat
	end tell
end if

I'm also a little curious about the "exit repeat" inside the tell statement. i wonder if it might not be better to do something like this:

Code:
if ((get name of the processes) contains "VisualHub") then
    -- nothing
    else
	tell application "FilesDone"
		activate
	end tell
	exit repeat
end if
 

HiRez

macrumors 603
Jan 6, 2004
6,250
2,576
Western US
I would put a delay in the loop as running that check continuously may starve the CPU.

EDIT: Oops, sorry, neutrino already mentioned that... :rolleyes:
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.