Applescript that searches for folders by name

I've set up a bunch of folder action scripts on our Xserve that changes the colour label of folders when they are dropped into specific folder, I use this to help organise which jobs are live and which are finished and ready for backup.

The system works well, but because there is a live work folder and finished work folder for each of our clients and each of these has a folder action attached, our server is taking quite a hammering with System events using huge processor cycles.

Someone kindly came up with the script below for a stay open script that would check the folders every 30 seconds and change the folder labels, which would be perfect, but it only finds "Live Work" and "Finished Work" folders on the desktop, All our Client folders are actually on a xserve RAID, so I need to modify the script so it seaches all of the RAID for folders called "live work" or "finished work" and batch changes the colour label.. any ideas?




property LiveWorkFolder : "Live Work"
property FinishedWorkFolder : "Finished Work"
property NoColor : 0
property Orange : 1
property Red : 2
property Yellow : 3
property Cyan : 4
property Magenta : 5
property Green : 6
property Gray : 7

on idle

tell application "Finder"

repeat with d in folder LiveWorkFolder

set label index of d to Green

end repeat

end tell

tell application "Finder"

repeat with d in folder FinishedWorkFolder

set label index of d to Red

end repeat

end tell

-- rerun this routine for constant surveillance
return -- rerun by default every 30 seconds
-- return 10 -- rerun every 10 seconds

end idle

Powerbook 15.2, Mac OS X (10.4)

Posted on Oct 3, 2006 2:55 AM

Reply
5 replies

Oct 3, 2006 4:08 AM in response to Kevin Neal

property LiveWorkFolder : "Live Work"
property FinishedWorkFolder : "Finished Work"
property MasterPath : "x" -- where 'x' is the path of the folder which contains the folders of the users, whose related folders contain the 'Live Work' and 'Finished Work' folders.
property NoColor : 0
property Orange : 1
property Red : 2
property Yellow : 3
property Cyan : 4
property Magenta : 5
property Green : 6
property Gray : 7

on idle

tell application "Finder"

set liveWorkFolder_List to every folder of entire contents of folder MasterPath whose name contains LiveWorkFolder
set FinishedWorkFolder_List to every folder of entire contents of folder MasterPath whose name contains FinishedWorkFolder

repeat with i in liveWorkFolder_List
set label index of every item in i to Green
end repeat

repeat with i in FinishedWorkFolder_List
set label index of every item in i to Red
end repeat

end tell

-- rerun this routine for constant surveillance
return -- rerun by default every 30 seconds
-- return 10 -- rerun every 10 seconds

end idle

Mac OS X (10.4.8)

Oct 3, 2006 6:59 AM in response to Kevin Neal

01. In your original post, you stated:

property LiveWorkFolder : "Live Work"
property FinishedWorkFolder : "Finished Work"

...; however, in your pictorial reply post - you show 'Finished Jobs' and 'Live Jobs'.

Also, as such - i do not know how your code works; since the 'LiveWorkfolder' and 'FinishedWorkFolder' properties, or - else where in your code you, do not supply a complete file path.

-----

02. Via 'Disk Utility' I created a disk image - titled 'RAID'. In 'RAID' I created three (3) folders {All-Clad, ASDA, and Bentley}, which each containing a 'Projects' folder; and each 'Projects' folder containing folders 'Finished Jobs' and 'Live Jobs'. In these last two (2) folders I place some randomly selected files.

The code below (based on my above posted code - which had 'on idle', 'return', and 'end idle' commented out) worked, as expected.

property LiveWorkFolder : "Live Jobs"
property FinishedWorkFolder : "Finished Jobs"
property MasterPath : "RAID" -- The name of the folder, or volume, which contains the folders of the users, whose related folders contain the 'Live Work' and 'Finished Work' folders.
property NoColor : 0
property Orange : 1
property Red : 2
property Yellow : 3
property Cyan : 4
property Magenta : 5
property Green : 6
property Gray : 7

on idle

tell application "Finder"

set liveWorkFolder_List to every folder of entire contents of folder MasterPath whose name contains LiveWorkFolder
set FinishedWorkFolder_List to every folder of entire contents of folder MasterPath whose name contains FinishedWorkFolder

repeat with i in liveWorkFolder_List
set label index of every item in i to Green
end repeat

repeat with i in FinishedWorkFolder_List
set label index of every item in i to Red
end repeat

end tell

-- rerun this routine for constant surveillance
return 30 -- rerun by default every 30 seconds
-- return 10 -- rerun every 10 seconds

end idle

-----

03. At least here (in 'on idle' ... 'end idle' ) ...

return

... by itself, does not imply 'return 30'. Thus, the reason for ...

return 30

... above.

Mac OS X (10.4.8)

Oct 3, 2006 8:32 AM in response to dev_sleidy

Cheers for the help, It worked fine on a mock up of the RAID with just a few folders, but as soon as I tried on the real thing it just hung the finder then gave an apple event timeout error. the RAID has 185 and a total of around 10,000 folders, so I guess this is too much.

could I somehow make the script just look in RAID/Projects, tried putting that as the masterpath but it just reported an error

Oct 3, 2006 9:34 AM in response to Kevin Neal

You could try adding 'with timeout of 0 seconds ... end timeout' before / after 'tell applications "Finder" ... 'end tell', as in ...

on idle

with timeout of 0 seconds
.
.
end timeout

end idle

... and / or, modify the code accordingly. Such as ...

property LiveWorkFolder : "Live Work"
property FinishedWorkFolder : "Finished Work"
property MasterPath : "RAID" -- The name of the folder, or volume, which contains the folders of the users, whose related folders contain the 'Live Work' and 'Finished Work' folders.

property excluded_List : {"Library", "System", "Users"} -- List of root level folders, to 'not' scan.
property users_List : {}

property NoColor : 0
property Orange : 1
property Red : 2
property Yellow : 3
property Cyan : 4
property Magenta : 5
property Green : 6
property Gray : 7

on idle

with timeout of 0 seconds -- May be optional.
tell application "Finder"

-- Generate a list of folders to scan through.
repeat with i in (list folder (MasterPath & ":") without invisibles) -- tList
if (not (excluded_List contains i)) then copy (MasterPath & ":" & (i as string) & ":") to end of users_List
end repeat

repeat with i in users_List -- Cycle through the sub-list of folders.
set liveWorkFolder_List to (every folder of entire contents of folder i whose name contains LiveWorkFolder)
set FinishedWorkFolder_List to (every folder of entire contents of folder i whose name contains FinishedWorkFolder)

repeat with j in liveWorkFolder_List -- Process files of 'liveWorkFolder' folders.
set label index of every item in j to Green
end repeat

repeat with j in FinishedWorkFolder_List -- Process files of 'FinishedWorkFolder' folders.
set label index of every item in j to Red
end repeat
end repeat

end tell
end timeout -- May be optional.

-- rerun this routine for constant surveillance
return 30 -- rerun by default every 30 seconds
-- return 10 -- rerun every 10 seconds

end idle

Mac OS X (10.4.8)

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Applescript that searches for folders by name

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.