Re: Modify (PowerMail script)
Re: Modify (PowerMail script)
- Subject: Re: Modify (PowerMail script)
- From: Kai <email@hidden>
- Date: Sat, 18 Jan 2003 19:51:33 +0000
on Wed, 15 Jan 2003 21:09:47 -0600, "Francine Mack" <email@hidden>
wrote:
>
tell application "PowerMail"
>
set theMessages to current messages
>
repeat with msg in theMessages
>
-- delete messages after ______ hours
>
"end "
>
How can I change this so that it works in PowerMail?
>
I don"t know how to finish this. It came as a sample script that allows
>
user to insert missing information.
>
TIA,
>
Francine Mack
I was kinda hoping someone with knowledge of PowerMail (ie. not me) might
run with this one, Francine. (Perhaps you've even had some help from one of
the other lists to which you posted the question).
However, just in case you haven't yet had a better offer, I thought I'd
throw in a couple of basic AS pointers - which may help to explain part of
the problem, at least.
Let's take a look at your script so far, line-by-line...
============================
tell application "PowerMail"
============================
This is the start of what's known as a tell block.
It's purpose is to let AppleScript know where to initially direct the
commands that follow. In this case, it confirms that "PowerMail" should be
the target application.
Unless a tell block can be squeezed into a single line[1], the script will
also need to confirm when to stop sending commands to the targeted
application. This is done by using the command: end tell[2].
===================================
set theMessages to current messages
===================================
The term 'current messages' would return a list of PowerMail's er... current
messages.
Besides getting the current messages, the purpose of this line is also to
assign the returned value (in this case, a list) to a variable
('theMessages')[3].
==============================
repeat with msg in theMessages
==============================
This line signifies the start of a repeat loop. When used in this way, the
main purpose of such a loop is to run through a list (represented here by
the variable 'theMessages') and evaluate or act upon each item in that
list[4].
Like a tell block, the end of a repeat loop also needs to be specified. To
do this, simply insert (at the appropriate point in the script): end repeat.
=====================================
-- delete messages after ______ hours
=====================================
The initial characters '--' signify that this line is a comment (text that
is ignored by AppleScript when a script is run).
Normally, I'd be tempted to try removing the '--' characters and replacing
the '______' with an integer, so that the line would read, say:
delete messages after 4 hours
However, because the line is in a repeat loop, which should be acting upon
the variable 'msg', it just doesn't look right to me. (And unfortunately,
since I'm not using PowerMail here, any suggestion about the correct syntax
would be purely guesswork on my part...)
======
"end "
======
This looks like an attempt to end the repeat loop. My guess is that this was
entered in response to a compile-time error message that went something like
this:
---------------------------------------
expected "end" but found end of script.
---------------------------------------
In spite of this, you're probably still getting a compile-time error -
except that it may now look more like:
---------------------------------------------------
expected end of line, etc. but found end of script.
---------------------------------------------------
That's partly because "end " is in quotes, so AppleScript will treat it as
text - rather than an instruction. You need to remove the quote marks.
In addition, the compiler will be expecting an end to the tell block, too.
So - to get the script to compile - you really need 2 'ends':
--------------------------------------
tell application "PowerMail"
set theMessages to current messages
repeat with msg in theMessages
-- delete messages after ______ hours
end
end
--------------------------------------
...which should compile as:
--------------------------------------
tell application "PowerMail"
set theMessages to current messages
repeat with msg in theMessages
-- delete messages after ______ hours
end repeat
end tell
--------------------------------------
(The automatic nesting of the compiled script should help you to see more
clearly where blocks start and end.)
Unfortunately, we're still not there yet. Even though we should now have
managed to get the script to compile, I'm still not too sure about that
commented line - which is crucial to getting the script to do anything
remotely useful.
You mention that the code came as a sample script that allows the user to
insert missing information. It looks to me like you may have already tried
adapting the original script (and full marks for making the effort).
However, posting the original here might just give someone a slightly better
clue about how best to adapt it for your particular purpose.
Sorry about the rather lengthy reply, but I get the impression that this may
be one of your first tussles with AppleScript - and I thought the extra
comments might help a little[5]. (In any event, I hope that I haven't added
to any confusion).
=========================================================================
--------------------------------
[1] Example of single-line tell:
--------------------------------
tell application "Finder" to display dialog "Hello"
----------------------------------------
[2] Example of multiple-line tell block:
----------------------------------------
tell application "Finder"
activate
beep
display dialog "Goodbye"
end tell
-----------------------------------------------
[3] Example of assigning a value to a variable:
-----------------------------------------------
A variable is simply a unique name for a value. This pseudo-code might help
to illustrate the principle:
tell application "Fruiterer" to set fruitBowl to current fruit -- [6]
--> {"apple", "pear", "orange", "banana"}
So from now on, instead of having to refer back to the original list
({"apple", "pear", "orange", "banana"}), the script can simply use the
variable 'fruitBowl'.
-----------------------------------------------
[4] Example of looping through each listed item
-----------------------------------------------
Try running this moronic effort:
set fruitBowl to {"apple", "pear", "orange", "banana"}
repeat with theFruit in fruitBowl
display dialog "mmm... " & theFruit & "..."
end repeat
display dialog "Doh! Where's my donut?"
------------------------------
[5] Further reference material
------------------------------
If your experience so far hasn't already put you off, you might also be
wondering how you can find out more about scripting with AppleScript.
While this kind of question crops up quite regularly here, I guess that's
just evidence of yet more new AppleScript users - so I make no apology for
repeating the advice. ;-)
You've already made a good start by trying to adapt an existing script.
Another excellent way of getting to grips with scripting an application
_was_ (pre-OS X) to hit Script Editor's record button, perform a few manual
actions in the target application - and then check to see if those actions
had been recorded by Script Editor. If they had, then the results could be
used or modified as required. At the moment, though, very few applications
are recordable in OS X. :-(
You can also check out a specific application's AppleScript dictionary. From
Script Editor's 'File' menu, select 'Open Dictionary...', navigate to the
required application and open it. (Alternatively, in the Finder, drag the
application and drop it onto Script Editor's icon.) Many dictionaries aren't
that easy to understand. They can be terse affairs - and lack (IMO) one
vital ingredient: examples. However, once you get into the habit of
referring to them, you may be able to glean some valuable extra clue to help
you achieve your aim.
Check out <
http://www.apple.com/applescript/resources/> where, among other
things, you can access the AppleScript Language Guide (often referred to
around here as the ASLG). You can either view this in HTML format - or
download it as a PDF. While the ASLG is now somewhat dated, it still serves
as a primary reference source for many of us.
A visit to <
http://maccentral.macworld.com/columns/briggs.shtml>, where
you'll find a series of enlightening articles by Bill Briggs, should also
prove rewarding.
Finally, of course, you still have an amazing resource in the help, advice
and discussions on this list. (I'm always learning something new here.)
---------------------------
[6] application "Fruiterer"
---------------------------
Before anyone asks... NO, I _don't_ know where you can download a copy.
In its favour, though, the name does lack the dreaded initial 'i' - which
should at least spare us a further round of those painful, 'iWatering'
puns...
(Ouch! Whoops - sorry! Just sorta slipped out!) ;-)
--
Kai
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.