• 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: Script works on my machine, returns 0 results on another
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Script works on my machine, returns 0 results on another


  • Subject: Re: Script works on my machine, returns 0 results on another
  • From: Alex Hall <email@hidden>
  • Date: Sun, 18 May 2014 00:55:14 -0400

There are no paths or folders. Everything is done in the Mail app, and nothing is accessed from or written to disk (if you don't count the clipboard content). The script is constantly changing as the user reports back to me, and the latest one has large parts commented out. Still…


set secondsToWait to 900
set btn_ok to "OK"
set btn_next to "Next"
set btn_useSent to "Use Sent mailbox"
set btn_chooseMailbox to "Select a Different Mailbox"
set btn_start to "Start"
set btn_cancel to "Cancel"
set targetMailbox to "Sent"

(*
set searchSentBool to display dialog "Would you like to search all sent messages, or type the name of a different folder to search in?" with title "Search Sent Messages?" buttons {btn_useSent, btn_chooseMailbox} default button 1
if button returned of searchSentBool is equal to btn_useSent then
set useSent to true
else
set useSent to false
end if
*)
set useSent to true

if useSent is false then
set mailboxPromptResponse to display dialog "Enter the name of the folder to be searched. Capitalization does matter: " default answer "Sent" with title "Folder to Search" buttons {btn_next, btn_cancel} default button 1 cancel button 2
if button returned of mailboxPromptResponse = btn_cancel then
return false
end if
set targetMailbox to text returned of mailboxPromptResponse as text
end if

set str_subject to "Subject"
set str_body to "Body"
(*
set fieldPromptResponse to choose from list {str_subject, str_body} with title "Choose Field to Search" with prompt "Search subject or body?" default items {str_subject} OK button name btn_next cancel button name btn_cancel
if fieldPromptResponse is false then
return false
end if
set searchField to fieldPromptResponse as text
*)
set searchField to str_body

(*
set searchPromptResponse to display dialog "Please enter a string to find in the " & searchField & " field of the emails in the " & targetMailbox & " folder: " default answer "" with title "Search String" buttons {btn_start, btn_cancel} default button 1 cancel button 2
if button returned of searchPromptResponse = btn_cancel then
return false
end if
set searchString to text returned of searchPromptResponse as text
*)
set searchString to "\"broadcast it\""

set messageCount to 0
set recipientCount to 0
set messagesInfo to {}
set totalMessages to 0

tell application "Mail"
if useSent is true then
if searchField is equal to str_subject then
with timeout of secondsToWait seconds
set foundMessages to messages in sent mailbox whose subject contains searchString
end timeout
else if searchField is equal to str_body then
with timeout of secondsToWait seconds
set foundMessages to messages in sent mailbox whose content contains searchString
end timeout
end if
repeat with m in foundMessages
set messageCount to messageCount + 1
repeat with r in (recipients of m)
set recipientCount to recipientCount + 1
set messageInfo to address of r
set my messagesInfo to my messagesInfo & messageInfo
end repeat
end repeat


else
repeat with a in accounts
try
if searchField is equal to str_subject then
with timeout of secondsToWait seconds
set foundMessages to (messages in (mailbox targetMailbox of account (name of a)) whose subject contains searchString)
end timeout
else if searchField is equal to str_body then
with timeout of secondsToWait seconds
set foundMessages to (messages in (mailbox targetMailbox of account (name of a)) whose content contains searchString)
end timeout
end if
on error errorText number errorNum
if errorNum is equal to -1728 then
display dialog "The Mail account " & (name of a) & " does not contain a mailbox called " & targetMailbox & "."
else
display dialog "Unknown error " & errorNum & ": " & errorText
return false
end if
set foundMessages to {}
end try
set my totalMessages to (my totalMessages) + (foundMessages count)
display dialog "Searching the " & targetMailbox & " folder of " & (name of a) & "."


repeat with m in foundMessages
-- display dialog "Found a message. Subject: " & (subject of m) giving up after 1
set messageCount to messageCount + 1
repeat with r in (recipients of m)
set recipientCount to recipientCount + 1
set messageInfo to address of r
set my messagesInfo to my messagesInfo & messageInfo
end repeat
end repeat
end repeat
end if
end tell

--remove duplicate addresses
set nonDuplicatedAddresses to {}
repeat with addr in messagesInfo
if addr is not in nonDuplicatedAddresses then
set nonDuplicatedAddresses to nonDuplicatedAddresses & addr
end if
end repeat

--join the addresses into a string
set oldDelim to text item delimiters of AppleScript
set text item delimiters of AppleScript to "
"
set addresses to (nonDuplicatedAddresses as text)
set text item delimiters of AppleScript to oldDelim

set the clipboard to addresses
display dialog "Found " & recipientCount & " addresses in " & messageCount & " matches, " & ((messagesInfo count) - (nonDuplicatedAddresses count)) & " of which were duplicates." with title "Complete" buttons {btn_ok} default button 1

On May 17, 2014, at 11:52 PM, 2551 <email@hidden> wrote:

Is the script localized with a path specific for your machine that needs to be changed for his machine? Re-chheck all the path addresses. There's likely a tiny typo in one of them.

Also, does the script rely on folder actions, and are your two machines running different versions of OS X? The syntax for folder actions changed at some point (in Mavericks I think or was it Mountain Lion?)

Of course, if we could see the script, it'd be a bit easier to help.

Best

Phil


On 18 May 2014, at 00:10, Alex Hall <email@hidden> wrote:

Hi all,
Still that mail script. It searches the emails in a certain folder for some text, and copies the addresses of the recipients of any found messages to the clipboard. On my machine it works great. On the Mac of a friend, the one who asked me to write the script, it returns 0 results. I had him send me some of the messages the script should be finding, and I forwarded them to myself (he mostly wants to search the Sent folder, so I wanted them in my own Sent folder for testing). They are found, yet on his Mac, the script always turns up 0 results. I know this is kind of vague, but is there anything I might try, or tell him to try? Is there a setting, something weird in Gmail (maybe his Sent folder isn't called Sent?), or some other idea that will get this to work?

--
Have a great day,
Alex Hall
email@hidden




--
Have a great day,
Alex Hall
email@hidden




 _______________________________________________
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

  • Follow-Ups:
    • Re: Script works on my machine, returns 0 results on another
      • From: "koenig.yvan" <email@hidden>
References: 
 >Script works on my machine, returns 0 results on another (From: Alex Hall <email@hidden>)

  • Prev by Date: event-driven scripts?
  • Next by Date: Re: Script works on my machine, returns 0 results on another
  • Previous by thread: Script works on my machine, returns 0 results on another
  • Next by thread: Re: Script works on my machine, returns 0 results on another
  • Index(es):
    • Date
    • Thread