• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Code won't work in Tell block
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Code won't work in Tell block


  • Subject: Re: Code won't work in Tell block
  • From: waynemelrose <email@hidden>
  • Date: Mon, 01 Sep 2014 12:04:44 +1000

A very similar question has been answered already today. 

In short, you’re calling a function from within an application that doesn’t know about the function. So you have to tell (in this case “Mail.app” ) that the script owns the function “clean_string” 

put a ‘my’ in front of the ‘clean_string’


set cleanedName to my clean_string(quotedName)

Wayne 


On 1 Sep 2014, at 11:55 am, Jennifer <email@hidden> wrote:

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:
http://www.superiorshelving.com/mfg/nexel/pages/wire-shelving-chrome.php
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
References: 
 >Code won't work in Tell block (From: Jennifer <email@hidden>)

  • Prev by Date: Code won't work in Tell block
  • Previous by thread: Code won't work in Tell block
  • Index(es):
    • Date
    • Thread