How do I make folder action to tell me when folder is 650MB?

First of all, I’m new to AppleScript, so please excuse my simple questions.
I’ve been trying to write a script to use as a folder action that tells me when a
certain folder reaches 650MB. So far I’ve had no luck.
In plain english here’s what I’d like to do.

Tell application Finder
Get size of folder UntitledFolder
If size is greater than 650 MB then disply dialog
“Time to brun a disc.”

Now how do I write that in AplpeScript?
Get Size gives me a number like 1.96534260+E
How do I Get the size of a folder in MB?
Then how do I write “if the size is greather than 650 MB”?

Thanks in advance…

P.S. I am using Panther (10.3)

Take a look at this code from Code Exchange.

Jon

This is not exactly what you are looking for, but it may help get you started…

http://scriptbuilders.net/category.php?search=itunes_2cd

You can try this:

Jon


[This script was automatically tagged for color coded syntax by Script to Markup Code]

This might be close to what you want. I haven’t tested much but it appears to work. Tested on OS X 10.2.8.

on adding folder items to this_folder after receiving added_items
	set folSize to convertByteSize from (size of (info for this_folder))
	
	if word 2 of folSize is "TB" or word 2 of folSize is "GB" then
		display dialog "Burn Baby Burn! Folder size: " & folSize
		return
	end if
	
	if word 1 of folSize is greater than or equal to 650 and word 2 of folSize is "MB" then
		display dialog "Burn Baby Burn! Folder size: " & folSize
	end if
end adding folder items to

to convertByteSize from byteSize -- by Nigel Garvey
	if byteSize ? 1.099511627776E+12 then -- Terabytes (2 ^ 40) 
		((byteSize / 1.099511627776E+12 div 0.01 / 100.0) as string) & " TB"
	else if byteSize ? 1.073741824E+9 then -- Gigabytes (2 ^ 30) 
		((byteSize / 1.073741824E+9 div 0.01 / 100.0) as string) & " GB"
	else if byteSize ? 1048576 then -- Megabytes (2 ^ 20) 
		((byteSize / 1048576 div 0.01 / 100.0) as string) & " MB"
	else if byteSize ? 1024 then -- Kilobytes (2 ^ 10) 
		((byteSize div 1024) as string) & " K"
	else
		(byteSize as string) & " bytes"
	end if
end convertByteSize

– Rob

Whoops, our forum didn’t render the “greater than or equal to” symbols, the ? marks in Rob’s script should be ≥

Nope, I guess not, and I didn’t notice! Thanks for the heads up, Greg. Let’s try again.

on adding folder items to this_folder after receiving added_items
	set folSize to convertByteSize from (size of (info for this_folder))
	
	if word 2 of folSize is "TB" or word 2 of folSize is "GB" then
		display dialog "Burn Baby Burn! Folder size: " & folSize
		return
	end if
	
	if word 1 of folSize is greater than or equal to 650 and word 2 of folSize is "MB" then
		display dialog "Burn Baby Burn! Folder size: " & folSize
	end if
end adding folder items to

to convertByteSize from byteSize -- by Nigel Garvey
	if byteSize is greater than or equal to 1.099511627776E+12 then -- Terabytes (2 ^ 40) 
		((byteSize / 1.099511627776E+12 div 0.01 / 100.0) as string) & " TB"
	else if byteSize is greater than or equal to 1.073741824E+9 then -- Gigabytes (2 ^ 30) 
		((byteSize / 1.073741824E+9 div 0.01 / 100.0) as string) & " GB"
	else if byteSize is greater than or equal to 1048576 then -- Megabytes (2 ^ 20) 
		((byteSize / 1048576 div 0.01 / 100.0) as string) & " MB"
	else if byteSize is greater than or equal to 1024 then -- Kilobytes (2 ^ 10) 
		((byteSize div 1024) as string) & " K"
	else
		(byteSize as string) & " bytes"
	end if
end convertByteSize

– Rob

Wow! You guys rock! What a great community! Thanks!

Presumably what’s wanted is a folder action something like this:

on adding folder items to thisFolder after receiving addedItems
  tell application "Finder"
    thisFolder's physical size >= 6.815744E+8 -- 650 * 2 ^ 20
  end tell
  if the result is true then
    tell application (path to frontmost application as string)
      display dialog "Time to burn a disc." buttons {"OK"} default button 1 with icon note
    end tell
  end if
end adding folder items to