File type and size checking?

I am trying to figure out how to write an AppleScript that will head to a directory, determine if a file with a certain extension exists, and if it does exist, if the file size is greater than a certain size. And run that check every so often. Hung up on how to look at all files in a certain folder, look for that extension and then see if the file size is past my threshold.

Ideas? Not too good with AppleScript.

You don’t necessarily need to use AppleScript if you are familiar with something else - the Cocoa API and various other scripting languages (Ruby, Python, shell, etc) provide methods that will do all that.

red_menace is correct but you can certainly do this with AppleScript.

To list a directory, use the Finder:

tell application "Finder"
	set desktopItems to document files of desktop
end tell

To filter based on extension:

tell application "Finder"
    set desktopItems to document files of desktop where name ends with ".txt"
end tell

To get a file’s size:

tell application "Finder"
    …
    set i to item 1 of desktopItems
    size of i
end tell

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

File type and size checking?
 
 
Q