PDA

View Full Version : Applescript assistance ?




m2uk
Aug 17, 2006, 06:22 AM
Hi. I am a non programmer who is "fighting" around a couple of limitations/issues with Quickeys to automate a rather repetitive task that my wife has given me (and no, it is not THAT ! ::) )

There are a couple of steps I need to undertake that are not very reliable with the "click in a location" features of Quickeys, perhaps in part to my inexperience with the program (but I have checked checked and checked and the behaviour is not always the same) but it results in data loss and stress.

I am NOT very experienced with AppleScript and the googling I have done hasn't yielded much that works.

(Assume there is an Apple Mail folder with 50 messages)

The steps I need to undertake are:

1. From Apple Mail select the message at the top of the view (each message is different and must be handled separately) (effectively "taking that asset")

2. Open the URL given in the message body of the message selected in step 1 (I have tried the Geturl statement but Quickeys claims that I have not defined a variable (!) yet Apple Script Editor doesn't mention this.

3. I can do the bits in the middle with Quickeys...

4. After the actions made with Quickeys have been done, I need to delete the message defined in step 1 (and this is where the problem has been as it doesn't always grab the right message to delete, perhaps due to new messages appearing in the view. Each message will have in the subject line a predictable subject line and a unique reference number if that helps.

And then with Quickeys I can loop back to the start.

Would anyone be kind enough to give me some tips :) Of a polite nature at least that will help me fight this problem and maybe get more into AppleScript.

Thanks in advance from Finland !



rob finch
Aug 20, 2006, 04:51 PM
Hi,

Each message has it's own unique ID. When you take the first message in the window, save it's ID in a variable, then delete the message using the ID as the reference.

An example would be :-

tell application "Mail"
set this_mailbox to mailbox "Test"
set this_message to the first message of this_mailbox
set message_ID to the id of this_message
set all_messages to every message in this_mailbox
repeat with each_message in all_messages
set each_message_ID to the id of each_message
if each_message_ID is equal to message_ID then delete each_message
end repeat
end tell

It's a bit crude, but it will work. You could try adding the message IDs to a delimited list, then deleting all messages with an ID in the list.

Hope this helps,

Rob.

m2uk
Aug 23, 2006, 11:43 PM
Thanks and sorry for the delay. I will go and get an Applescript book and try and understand what you've kindly wrote as I tried dropping it in Quickeys and it didn't do anything (but I suspect that is down to me being a dimwit !)

But it gives a few more clues.

Best wishes. !