Please, stop the noise!!! Finder system sound issue...

Hello! New scripter here, loving it, but I’m trying to learn under pressure (job for a client, was not ready for it when my boss sold it) from here, Google, and the “AppleScript 1-2-3” book. Not the best way to learn, but I haven’t a choice.

I have some code I need to build, which will move a bunch of files from one folder on a network share to a different share, building new folders as needed.

I think I have this figured out, VERY simple AS code, no UNIX help, but I have a problem which is slowing the processing of the folders down. Every file to be moved is labeled yellow in Finder, then moved, then repeated until done. However, every time the file is moved, I get a system sound. So in a folder of 300 files, the script has Finder playing the system “chink” sound 300 times, which is taking forever.

If it was a matter of just muting the system temporarily for 10 moves, that’d be OK, but this is definitely slowing processing down.

Of note (possibly), I’m developing this on 10.8, but the code will be run on machines running 10.6 and 10.7. So far, this has only been tested on my 10.8 machine.

Here’s my code, with the problem child in the section labeled ‘move PNG files to temp folder’:

tell application "Finder"
	set thisFolder to choose folder with prompt "Choose the destination folder" as string
	-- Make sure sub folder exists
	if not (exists folder "temp" of thisFolder) then
		set tempFolder to make new folder at thisFolder ¬
			with properties {name:"temp"}
	else
		set tempFolder to folder "temp" of thisFolder as alias
	end if
	
	if not (exists folder "save" of thisFolder) then
		set saveFolder to make new folder at thisFolder ¬
			with properties {name:"save"}
	else
		set saveFolder to folder "save" of thisFolder as alias
	end if
	
	-- move PNG files to temp folder
	set theseFiles to every file in thisFolder
	repeat with thisFile in theseFiles
		if name extension of thisFile is "png" then
			set the label index of thisFile to 3
			move thisFile to tempFolder
		end if
	end repeat
	
	-- Get the file list
	set thePNGFiles to every file of tempFolder as alias list
	-- ...
	-- There's more going on here, but not of real concern...
end tell

Thanks for any help you can spare!
Dan

Don’t know if this gets at your problem, but you could do something like this at the start of your routine:


set originalVolume to output volume of (get volume settings)
set volume output volume 0

Then do something like this at the end of your routine:


set volume output volume originalVolume

Yes, thank you, I had thought about doing that, and had seen another thread on this site which came up with the same conclusion, though the file count for my project is a much larger problem. My code will, at times, need to process upwards of 1000 files daily.

Maybe I’m going about this the wrong way. Actually, I’m sure I am, but I don’t have a good enough grasp of alternative file access methods (bash scripting in UNIX, mainly) to learn the command structure. sed and awk–not fun to learn. Anyway, I’m taking a list of the folder in question, and using a repeat-if/endif-end repeat structure, which I’m sure is not speedy and which Finder sees as a separate event for each moved file, thereby triggering the system sound for each file move, chewing up processing time.

Thanks!

Hi,

Try doing the investigation and copying in separate phases,
that is, build yourself a list of files to move first,
then delegate that to the finder.

Here’s a sample operation that works for me
(single operation):


property targetFolderMacPath : "Iomega-1T-C:Users:manoahfadams:Desktop:x:"
property targetLabelColorIndex : 1 -- orange
tell application "Finder"
	set fileList to the selection
	set actionList to {}
	repeat with f in fileList
		if label index of f is targetLabelColorIndex then
			set end of actionList to f
		end if
	end repeat
	move every item of actionList to folder targetFolderMacPath
end tell

As applied to your script, it should look like:


	-- move PNG files to temp folder
	set theseFiles to every file in thisFolder
	set actionList to {}
	repeat with thisFile in theseFiles
		if name extension of thisFile is "png" then
			set the label index of thisFile to 3
			set end of actionList to thisFile
		end if
	end repeat
	move every item of actionList to tempFolder

Model: PPC G4 Dual-800Mhz
AppleScript: 1.10.7
Browser: Safari 533.19.4
Operating System: Mac OS X (10.4)

I see, using that move statement after the repeat, that makes more sense now that I see it.

The folder is a “live” folder on a server, with photographers in the studio taking product shots constantly, so the idea of labeling the files first, then moving only those files, should leave behind new files in a fairly trackable state. Could I change that last line to:

move every item of actionList with label index of 3 to tempFolder

Or am I being too literal for AS?

Thanks so much for the guidance!

EDIT: I think I’m too tired for this tonight. I now see that “every item in actionList” is already all of the labeled files, so there would be no need to call that out. However, for giggles, would the statement above be grammatically correct (in some other script, say) in AppleScript?

Hi abandonedbrain,

I think you can turn off the sound at System Preferences > Sound > Sound Effects, and uncheck “Play user interface sound effects”. You probably can use ui element scripting to turn it off and on in your script.

Edited: here’s a script to toggle the sound from your script.

tell application "System Preferences"
	activate
	set current pane to pane id "com.apple.preference.sound"
end tell
tell application "System Events"
	tell process "System Preferences"
		tell window 1
			tell tab group 1
				click checkbox "Play user interface sound effects"
			end tell
		end tell
	end tell
end tell

You could do more like check if it is already off first.

gl,
kel