hi to all!!!
well i couldn’t find a better way to sumarize my question for the subject so, forgive me if thats a deceiving title.
here is the case, i want to make a script ( i’ve been thinking of a folder action ), that tells me if there are files or folders in a folder.
let me explain with an example:
i have a folder A on my desktop. i want that whenever i put a file or folder in that folder A, its label changes to RED. and then, whenever the folder is empty, i want the label to change to NONE. and so on… it would have to change any time i add or remove files or folders from A.
i don’t know how to make a script to react to changes in a folder without it to be running all the time…
once, i’ve used Lingon to mount a daemon that was supposed to be continuosly running in the background ( but i don’t remember for what i’ve used it… )
anyway, if you could enlighten me on how to make it react to the changes inside a folder constantly, that would be great, i think i could handle the code from then on.
thank you very much to all!!!
M.
This works for me (6 is an ugly green)
on adding folder items to LabelingFolder after receiving filesOrFolders
tell application "Finder" to set label index of LabelingFolder to 6
end adding folder items to
on removing folder items from LabelingFolder after losing filesOrFolders
tell application "Finder" to set label index of LabelingFolder to 0
end removing folder items from
right.
thats like a good slap in the face.
i love the code.
i just couldn’t see that option because i thought about the “on adding” or “on removing” like if they were “on run”… so the “logical” thing to think is “its impossible to put two or more ‘on run’ sentences on a single script”.
well… that was a complex thing to explain, and my english is pretty rusty.
bottom-line: than you very much.
M.
Hi,
as you mentioned Lingon, the smartest way to to this is to create a launchd agent:
¢ create this AppleScript and save with somewhere (adjust the path to the “hot folder”)
set labeledFolder to ((path to desktop as Unicode text) & "LabeledFolder")
tell application "Finder"
set isEmpty to (((count items of folder labeledFolder) = 0) as integer) + 1
set label index of folder labeledFolder to item isEmpty of {2, 0}
end tell
¢ create with Lingon an launchd agent with these parameters (change the paths to the script and the watched folder)
and load it
[code]<?xml version="1.0" encoding="UTF-8"?>
Label
watch_folder
LowPriorityIO
Program
/usr/bin/osascript
ProgramArguments
osascript
/full/path/to/script.scpt
ServiceDescription
Applescript when contents of folder changes
WatchPaths
/full/path/to/watched/folder/
[/code]
membranatus:
I know they pretty colors are nice and all but for a quick view turn on “Show Item Info” in the View Options for the Finder. On the Desktop or in Icon View in a Finder window you will see the number of items contained in the folder.
Jim Neumann
BLUEFROG
BLUEFROG:
OMFG.
( but at least i practiced a little with that now useless script/folder action… hehe )
thanks!!!