Beep vs Say

Good morning.

I’m new to AS and have been working through my first script. I need to attach a script to a folder as a folder action to test for the arrival of new files and then set a comment which Spotlight will subsequently index. I wasn’t seeing the results I thought I should so I added a couple of lines:

Beep X

through out the script so that I’d have audible evidence that the script was being triggered.

What surprised me is that upon downloading another file, the machine did not beep. Given this, I replaced the Beep statements with “Display Dialog” statements so I could rely on visual evidence instead. Upon downloading another file, the dialogs display… hmmmm The script was running, but beep didn’t work…

so, I added “say” statements into the script instead of beep and the say statements DO work.

curiosity is setting in and given that say works, but beep doesn’t I was wondering if this had been seen before. I’ve verified that “flash the screen” when an alert sounds is UNchecked and given I get audible feedback from say yet not beep am stumped on where to turn next.

Many thanks in advance

Model: 2.4GHz Intel Core 2 Duo MBP
Browser: Safari 525.28.3
Operating System: Mac OS X (10.5)

well ~ rebooting has restored audible BEEP output, but I’m still curious if there is a series of events which brought this about. Now that I have sound again, I need to figure out a way to efficiently trace through the script to see what the values are as it executes.

Upon downloading a file, there are 2 files which get added to the directory:


the mov file has a size of ZERO and the PART file increments as the file downloads. I had missed this nuance when I thought about the downloading process but when I “heard” the isGrowing loop get traversed again, I realized that addedItems was a list of 2 files even though I was only downloading one.

Is there a way to get “verbose” output where a log file is created as the script runs and records the value of each of the variables?

found on MacScripter by Jeff Case and CaptNSwing.  Essentially isDone with lsof logic from CaptNSwing
Goal is to set a Folder Action to watch for the completion of new files arriving and then set a comment for spotlight use
I have added display dialog stmts  and say stmts to trace the execution of the script

-- commented out the following lines once I verified the script was running; had added these whilst BEEP wasn't working to force the running of the script

--set thisFolder to choose folder
--set addedItems to (choose file with multiple selections allowed)
--display dialog "going to loop for file(s) added"
-- say "going to Loop"

--folder action handler
on adding folder items to thisFolder after receiving addedItems
	say "new files arriving"
	-- do for every added item
	repeat with thisItem in addedItems
			--process added items one after another
			ProcessItem(thisFolder, thisItem)
		end try
	end repeat
	display dialog "returned from ProcessItem"
	say "done"
end adding folder items to

on ProcessItem(thisFolder, thisItem)
	say "got to ProcessItems Handler"
	--check if file is growing using UNIX "ls" command
	set LastFileSize to -1
	set isGrowing to true
	repeat until isGrowing is false
		say "listing file for size"
		set CurrentFileSize to do shell script ("/bin/ls -l " & (quoted form of (POSIX path of (thisItem))) & " | /usr/bin/awk '{print $5}'")
		if CurrentFileSize is equal to LastFileSize then
			set isGrowing to false
			say "file is here"
			set LastFileSize to CurrentFileSize
			delay 5 -- wait 5 seconds before getting size of new file for comparison to last value
		end if
		say "full file not here yet, looping again to is growing"
	end repeat
	--check if file is busy using UNIX "lsof" command
	set isbusy to 1
	say "got to isBusy Handler"
	repeat until isbusy is 0
		set isbusy to ((do shell script ("echo `lsof " & (quoted form of (POSIX path of (thisItem))) & " | wc -l`")) as integer)
		if isbusy is not equal to 0 then
			delay 5
		end if
	end repeat
	--once the script arrives here, the file in question is not growing and is not busy anymore
	--this has been tested for all kinds of file sizes (up to 1,2GB) and protocols (FTP, SMB)
	say "processItem is finished, and file is on disk and available - ready to add comment"
	--now that the file is ready, begin your processing
	--you should check here if the file exists, because the Windows copy process could have been aborted by the user
end ProcessItem