Can someone help me out and explain why this does not work?
on adding folder items to this_folder after receiving added_items
try
tell application “Finder”
set label index of every item in the added_items to 2
end tell
end try
end adding folder items to
Thanks
Model: Dual G5 (PowerMac)
AppleScript: 1.10.7
Browser: Safari 419.3
Operating System: Mac OS X (10.4)
‘added_items’ is a list, so you’ll have to repeat through the items of the list to set the labels individually. The Finder doesn’t (but should) know how to alter properties of every item of a list.
Finder can, however, get and set properties of a folder’s items collectively (and appropriately filtered, if required). For example:
tell application "Finder" to set label index of (choose folder)'s items whose name starts with "a" to 2
There’s also a potential issue when setting certain properties using Folder Actions ” especially if the operation involves some heavy lifting (such as copying large items to the target folder). Since the label index is among the last of an item’s properties to be copied, it could be reset to the original value after the script has already set it to the required value.
It might therefore be an idea to include some sort of checking routine, so that any progress window is dismissed before the properties are set ” perhaps something like this:
to check_progress()
tell application "Finder" to tell (first window whose class is «class prwd»)
repeat 5 times
if exists then exit repeat
delay 0.1
end repeat
repeat while exists
delay 0.2
end repeat
end tell
end check_progress
to get_names of l at f
set {d, f, text item delimiters} to {text item delimiters, f as Unicode text, ""}
set {l, text item delimiters} to {(l as Unicode text) & f, ":" & f}
set {l, text item delimiters} to {l's text items, f}
set {l, text item delimiters} to {(l as Unicode text)'s text items 2 thru -2, d}
l
end get_names
on adding folder items to this_folder after receiving added_items
check_progress()
set l to get_names of added_items at this_folder
tell application "Finder" to set label index of (this_folder's items whose name is in l) to 2
end adding folder items to
I got the following parts of your script to work when files were added to a folder
to get_names of l at f
set {d, f, text item delimiters} to {text item delimiters, f as Unicode text, “”}
set {l, text item delimiters} to {(l as Unicode text) & f, “:” & f}
set {l, text item delimiters} to {l’s text items, f}
set {l, text item delimiters} to {(l as Unicode text)'s text items 2 thru -2, d}
l
end get_names
on adding folder items to this_folder after receiving added_items
set l to get_names of added_items at this_folder
tell application “Finder” to set label index of (this_folder’s items whose name is in l) to 3
end adding folder items to
I simply want files under 1000 kb to change to yellow and over 1001 kb to green when automatically added to the folder. Being able to make a criteria of file type would be great also (.avi aren’t included or .doc are only changed). Any help would be greatly appreciated.
Model: new MacBook
AppleScript: 2.1.1 (81)
Browser: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.0.7) Gecko/20060911 Camino/1.0.3
Operating System: Mac OS X (10.4)
So you’re saying that you want to get all the files in a chosen folder whose name extensions are “doc” for example, and if they are larger than 1001 KB change their label to green, else set their label to yellow? Do you want this to be a Folder Action, or are you going to choose the folder? In either case, will the items dropped or the contents include folders whose files you want included?