Hi all,
I am really really struggling to understand where i need to add tell application ‘mail’ event within this code. I am trying to monitor a folder for new files, then when received send an email. I have taken this code from a previous posting it this code partly correct to perform my request. I am new to apple scripting.
The code is as follows:
global dirToMonitorize, idleAmount, dirToMonitorizePP, detectedItems, queueItems, queueSizes
set dirToMonitorize to alias "myfolderpath"
set idleAmount to 2
to processItem(filespec)
tell application (path to frontmost application as text) to ¬
display dialog (name of (info for filespec)) & return & return & ¬
"Finished: " & (time string of (current date)) with icon 1 giving up after 5
end processItem
set dirToMonitorizePP to POSIX path of dirToMonitorize
set detectedItems to list folder dirToMonitorize without invisibles
set queueItems to {}
set queueSizes to {}
on idle
set itemLst to list folder dirToMonitorize without invisibles
if itemLst is not detectedItems then addNewItems(itemLst)
if queueItems is not {} then monitorize()
return idleAmount
end idle
to monitorize()
set itemsInProcess to {}
repeat with i from 1 to count queueItems
set itemToMonitorizeNewSize to get eof of ¬
(POSIX file (dirToMonitorizePP & queueItems's item i))
if itemToMonitorizeNewSize is queueSizes's item i then --> item stopped growing
processItem(POSIX file (dirToMonitorizePP & queueItems's item i))
set itemsInProcess's end to i
else
set queueSizes's item i to itemToMonitorizeNewSize
end if
end repeat
--> remove items sent to process from queue
set queueItems to strip(itemsInProcess, queueItems)
set queueSizes to strip(itemsInProcess, queueSizes)
end monitorize
to addNewItems(itemLst)
repeat with i from 1 to count itemLst
if itemLst's item i is not in detectedItems then
set detectedItems's end to itemLst's item i
set queueItems's end to itemLst's item i
set queueSizes's end to 0
end if
end repeat
end addNewItems
to strip(itlst, lst)
script o
property a : lst
property nl : {}
property b : itlst
end script
set o's b to o's b as list
repeat with i from 1 to count lst
if i is in o's b then
else
set o's nl's end to o's a's item i
end if
end repeat
o's nl
end strip