I’m new in apple script and I was trying to create a script that sends me a mail whenever a file is dropped in a folder. This mail should include some info about the file and attach the file itself to the mail. I have found a script provided by apple that does approximately the same, the name is ADD - NEW ITEM ALERT I edited to fit my needs. but I have had some problems with the path of the attachment… the attachment isn’t being attached to the mail.
That is the script that is not working!! Even tough if you write in the code:
--all the code until the comment mark then add this
set theAttahment to "" & (added_items)
display dialog the theAttachment
--then continue the code
the correct path name will pop!!
if u put in the code:
--all the begening code till you reach the comment mark
set theAttachment to choose file
--all the code other code till you reach the attachment part again
make new attachment at after the last paragraph with properties {file name:theAttachment}
it will work but you will have to choose the attachment manually… i don’t want that … i think this can be solved easely by someone who knows what he’s doing [unlike me…] please i need help urgently…
your guess turned out to be working… =)…
but i need one more thing, i need to get the size of the folder/file attached how can this be done?
I tryed to use the “data size” function but it was always returning a zero… any sugestions?
well i have been working on the same subject, i needed to find the size of a certain folder.
The thing is that on adding file, i am sending an email with this attached file or folder but if its size was bigger than 5 MB it wont b attached.
So i want to reject files or folders greater than 5 MB. To do so i have to know the size.
What i am doing is always returning me a zero value.
tell application "Finder"
activate
data size of added_items
display dialog the (data size)
end tell
Please can you write me a more detailed script because the one of the physical size didnt work. I dont know if there is something missing.
Thnx a lot!!
tony
Model: Mac OS X Server
Browser: Safari 125.9
Operating System: Mac OS X (10.3.5)
I don’t know quite what to say. I played around with this test script a little.
on adding folder items to thisFolder after receiving addedItems
tell application "Finder"
repeat with anItem in addedItems
if class of anItem is folder then
set theSize to physical size of every item in anItem
else
set theSize to the physical size of anItem
end if
display dialog theSize as string
end repeat
end tell
end adding folder items to
It will return “missing value” if I try to copy a folder to the location and then if I drag the copy out and then back in it returns the physical size. If I just drag the original folder in it works fine. If I copy a file it has no problems. I don’t know if this is a referencing problem or maybe a bug?
Maybe we can get Nigel, JJ or Jobu or one of the other more learned gurus to help with this one. I’ll keep trying though.
PreTech
An edit to this post: I have found that my line: if class of anItem is folder then is at fault somehow. The class of the item returned is alias so it does not seem to reference the actual folder itself. Still working on it though.
Model: dual 1.8 G5
AppleScript: 2.1 (80)
Browser: Safari 412.5
Operating System: Mac OS X (10.4)
on adding folder items to thisFolder after receiving addedItems
set newList to {}
tell application "Finder"
set theList to every item of thisFolder
repeat with anItem in theList
set theName to name of anItem
display dialog "the name is " & theName
if class of anItem is folder then
display dialog "folder"
set theSize to size of anItem
else
display dialog "file"
set theSize to the physical size of anItem
end if
display dialog "The size is " & theSize as string
end repeat
end tell
end adding folder items to
However, you’ll need to get rid of any files already in the folder that this would be attached to unless you don’t mind it going through items already in there. I’m having problems with the addedItems and those being alias references. I can’t figure out how to reference the actual folder or file. Probably something simple. Hope this helps.
P.S. The dialogs are there for troubleshooting purposes.
PreTech
Model: dual 1.8 G5
AppleScript: 2.1 (80)
Browser: Safari 412.5
Operating System: Mac OS X (10.4)
Just jumping in here but this might help. Although I not sure about the details of the particular problem:
on adding folder items to thisFolder after receiving addedItems
tell application “Finder”
repeat with anItem in addedItems
set k to kind of anItem
if k = “Folder” then
set theSize to the size of anItem
display dialog theSize as string
else
set theSize to the size of anItem
display dialog theSize as string
end if
end repeat
end tell
end adding folder items to
It worked fine and explains the missing value error caused by the position of the display dialog in the loop.
Thank you guys for the help. I had things working because of you.
But i am facing a new porblem now. it might be related to applescript bug or not.
Anyways this whats happenin, in my work i need to control every delivered file or folder to a certain location so this why on adding files or folders to a certain places i ll receive an email. the problem is that a client delivered a file which was already there, he will be asked to replace and if he does my script wont work although he sent a new file with different information.
Help me on this one guys!!
thx!!
You could make a new folder so when an item is placed, and the email sent, the new item is then moved to the new folder that way the folder being checked for new items is always empty. Maybe?
This cannot work. I forgot to tell you that those client have write only access to the delivered folder and there are other clients that have read only access and i am in a different bldg. so i need to know whats going on.
I cannot delete the files directly because as i said there are people who needs them.
Sorry for the disturbance…!! if you can do something about it…if not its okay i ll see what i ll do…!!
thx again!
Okay, i think this could be one of the solutions, i thought of an application that chechs the name and if a name already exists it would delete the new item…but i think ur idea is better…the thing is that i dont know how to handle the date scripts yet…Can you send me any tips related to this subject and my previous code…!!
thx!
Riverman here
Don’t see the problem with PreTech’s suggestions. It’s not you or the users that do the moving/deleting of the files but the mail script. Or am I missing something
property fileList : {}
on idle
tell application "Finder"
set theFolder to folder "theDest" of desktop -- your folder location
set theTime to the time of (current date)
set testDate to (current date) - theTime -- the current day at 12:00 AM
--display dialog theDate as string
set fileList to every item of theFolder
if time of (current date) is greater than or equal to 21600 then -- 6:00 AM current day
repeat with anItem in fileList
if modification date of anItem is greater than testDate then
display dialog "Send message" -- this is where your email code would go
end if
end repeat
end if
end tell
end idle
The property stays the same until you change it in the script or recompile the script.