AppleScriptObjC - Check for Fule

Hi all -

I’ve got an applescriptobjc app that basically asks the user some to fill out a form, select a file, and then feeds the file to compressor. After compressing is done, it should pop up a dialog box sending folks to safari, where they upload their movie. This currently isn’t working. I’ve got everything linked up properly (delegates- interface builder), but can’t seem to make this work. Here’s a relevant chunk of the code:

            
set file1 to (full_quality_file_a & "-_4x3_cmfupload.mov") as string
            set file2 to (full_quality_file_a & "-_16x9_cmfupload.mov") as string

            repeat
				if exists file1 then
                    tell current application
                        activate
                        set the var to "yes"
                    end tell
                end if
                
				if exists file2 then
                    tell current application
                        activate
                        set the var to "yes"
                    end tell
                end if
				delay (30) -- delay 30 seconds
			end repeat
            tell current application
                if var = "yes" then
                encodeWindow's orderOut_(me)
                congratsWindow's makeKeyAndOrderFront_(me)
                end if
            end tell



basically, having it watch a folder and see when the file name is correct, indicating compressor is finished with the file. When I move the orderOut and makeKeyandOrderFront commands into the repeat, the desired functionality occurs, but the button on the dialog box is non-responsive [I believe because its stuck in the repeat]. Any ideas or thoughts would be greatly appreciated.

FYI, We’re using FCPX primarily; I haven’t been able to do much from the CLI with the new Share Monitor.

Thanks!

That’s not going to do anything like that. You need to ask either Finder/SystemEvents, or NSFileManager.

You also have several other problems with the code you posted. The tell current application blocks are unnecessary, the repeat loop you have is infinite, and it is bad programming practice to use the delay command in ASOC. It would be better to use a timer, and use the file manager to check for the existence of the files. The following example should get you close to what you want. You would need to change the definition of pathToRoot to whatever folder you are looking in to find your files:

script CompressAppDelegate
	property parent : class "NSObject"
	property pathToRoot : POSIX path of ((path to desktop folder as string) & "CompressedFiles:")
	property manager : missing value
	property file1 : missing value
	property file2 : missing value
	
	on applicationWillFinishLaunching_(aNotification)
		set manager to current application's NSFileManager's defaultManager()
		set file1 to (full_quality_file_a & "-_4x3_cmfupload.mov") as string
		set file2 to (full_quality_file_a & "-_16x9_cmfupload.mov") as string
		current application's NSTimer's scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(10, me, "checkFiles:", missing value, 1)
	end applicationWillFinishLaunching_
	
	on checkFiles_(sender)
		set var1 to manager's fileExistsAtPath_(pathToRoot & file1)
		set var2 to manager's fileExistsAtPath_(pathToRoot & file2)
		if var1 as integer = 1 or var2 as integer = 1 then
			log "found File"
			encodeWindow's orderOut_(me)
			congratsWindow's makeKeyAndOrderFront_(me)
			sender's invalidate() -- this stops the timer
		else
			log "No File Found"
		end if
	end checkFiles_
	
end script

Ric

Ric, Shane - Thanks much. I really appreciate it. Still got a lot to learn.