Hello,
I'm having a problem with the following script and I could use some help. clean_string() does not work inside the tell Mail block and the script stops there. If I remove that portion of code and run it by itself, everything executes properly. Can someone spot what's wrong? I'm at a loss. It's running under OS X 10.4.11.
Everything was running fine until I added the clean_string() subroutine. The reason I added that was just to strip out the characters "(", ")", "-", and spaces from the Subject. I'm trying to turn this: "Greeting (404) 456-8897" into this: "greeting4044568897". I know it's probably overkill so if there's a better way to do that, I'd appreciate hearing about it. Thanks!
on perform_mail_action(ruleData)
-- The folder to save the attachments in (must already exist)
set attachmentsFolder to "Mac_HD:Library:Application Support:Phlink Items" as text
set AppleScript's text item delimiters to {""}
-- Get incoming messages that match the rule
tell application "Mail"
set selectedMessages to |SelectedMessages| of ruleData
repeat with theMessage in selectedMessages
-- Save the attachment
repeat with theAttachment in theMessage's mail attachments
set originalName to the subject of theMessage
set quotedName to quoted form of originalName
set cleanedName to clean_string(quotedName)
set lowerName to do shell script "echo " & cleanedName & " | tr A-Z a-z;"
set savePath to attachmentsFolder & ":" & lowerName & ".m4a"
tell application "Finder"
if file savePath exists then delete file savePath
end tell
delay 1
try
save theAttachment in savePath with replacing -- "with replacing" doesn't seem to work. I had to have the Finder (above) delete the file (above) first before saving the new one.
end try
end repeat
end repeat
end tell
end tell
tell application "Ovolab Phlink" to activate
end perform_mail_action
-- -----------------------------------------------
on clean_string(TheString)
-- Remove all characters except alphanumeric
set potentialName to TheString
set legalName to {}
set legalCharacters to {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"}
with timeout of 10 seconds
repeat with thisCharacter in the characters of potentialName
set thisCharacter to thisCharacter as text
if thisCharacter is in legalCharacters then
set the end of legalName to thisCharacter
if length of legalName is greater than 32 then
return legalName as text
end if
end if
end repeat
end timeout
return legalName as text
end clean_string
Thank you,
Jenni
Superior Shelving Systems::::....
The (Storage|Office|Home|Warehouse) Shelving Specialists
Since 1984
Wire LAN Shelving:
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives:
http://lists.apple.com/archives/applescript-users
This email sent to email@hidden