Comments, please.
Comments, please.
- Subject: Comments, please.
- From: Mr Tea <email@hidden>
- Date: Wed, 06 Nov 2002 16:01:45 +0000
Creak... grind... clank... another script rolls off Mr Tea's Heath Robinson
production line.
This one is part of a stay-open 'process monitor' script that sets up
'watched folders' for applications in a specified list when they are
running. I've tried to design it so that more apps can be added without
having to alter much of the script. As always, AS provides a gazillion ways
to approach this task, and there may be a better method than the one I've
cobbled together. Please let me know if I've committed any unspeakable faux
pas.
--=========================================START
property theApps : {"Adobe Illustrator", "Adobe Photoshop"}
property theFAs : {"Illustrator Export FA", "Photoshop Export FA"}
property AIX : alias "Studio!:Studio Files:Graphics:Export:Illustrator:"
property PSX : alias "Studio!:Studio Files:Graphics:Export:Photoshop:"
property theRunner : alias "Studio!:Studio Files:Scripts X:Actions:Simple FA
Runner"
property thePause : 15
set theFolders to {AIX, PSX}
on idle
tell application "System Events" to set appList to (name of every process)
as string
tell application "Finder" to set winList to target of every Finder window
as alias list
set asTid to AppleScript's text item delimiters
repeat with n from 1 to count of theApps
set AppleScript's text item delimiters to item n of theApps
if (count of text items of appList) > 1 then
if item n of theFolders is not in winList then
if item n of theFAs is not in appList then
tell application "Finder" to open item n of theFolders using theRunner
end if
end if
end if
end repeat
set AppleScript's text item delimiters to asTid
return thePause
end idle
--=========================================END
Are properties being used correctly? Is the script doing any needless hard
labour? Will this bring my system to its knees? And why does finding a
string in a list of strings take longer than finding a substring in a chunk
of text? In the test script reproduced below, searching for a name in a list
of names takes significantly longer than searching for that name in a string
containing all the names in the list. Searching for a name by using it as a
text item delimiter and checking if text can be broken up with it is
quickest.
--=========================================START
property oodles_of : 50000
tell application "System Events" to set appList to name of every process
set theString to appList as string
set theApp to "SystemUIServer"
set {asTid, AppleScript's text item delimiters} to {AppleScript's text item
delimiters, theApp}
set T1 to time of (current date)
repeat oodles_of times
set x to count of text items of theString
end repeat
set T2 to time of (current date)
repeat oodles_of times
set x to theApp is in theString
end repeat
set T3 to time of (current date)
repeat oodles_of times
set x to {theApp} is in appList
end repeat
set T4 to time of (current date)
set AppleScript's text item delimiters to asTid
{TidSearch:T2 - T1, StringSearch:T3 - T2, ListSearch:T4 - T3}
--=========================================END
Of course, the difference would be irrelevant in most cases, and including
the string coercion and getting/setting/restoring of TIDs in the equasion
muddies the waters somewhat...
Regards
Mr Tea
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.