Re: Oh-oh, another victim to scripting Mail [SOLVED!]
Re: Oh-oh, another victim to scripting Mail [SOLVED!]
- Subject: Re: Oh-oh, another victim to scripting Mail [SOLVED!]
- From: Dave Stewart <email@hidden>
- Date: Tue, 24 Jun 2003 17:17:28 -0700
At 3:55 PM -0700 20/06/03, I wrote:
>
> I've started with these meager beginnings:
>
>
>
> tell application "Mail"
>
> quit
>
> end tell
>
>
>
> delay 10
>
>
>
> tell application "Mail"
>
> activate
>
> check for new mail
>
> end tell
>
>
>
> What's throwing me isn't the fact this doesn't work (although that
>
> fact
>
> probably should), but the fact that each half by itself does!
On Saturday, June 21, 2003, at 10:17 AM, Marc K. Myers offered this:
>
>
This worked fine on my system:
>
>
tell application "Mail.app" to quit
>
delay 10
>
tell application "Mail.app" to activate
>
>
You don't need to tell Mail to check for new mail because it does that
>
automatically when you fire it up.
>
>
I'm running OS 10.2.6 and the second Mail beta.
>
>
Marc [06/21/03 3:01:25 AM]
I haven't a clue why this works and the above doesn't, but why fix what
ain't broke?
I wanted to thank Marc, Emmanuel and Runner for their ideas and
suggestions. Marc's suggestion is the one I went with, mostly because
it was so similar to what I was originally doing. In case anyone would
be interested in the script (now or in the future), here's what I've
hacked together. Keep in mind the script is run by a crontab task at 5
in the morning (before anyone shows up for work), which keeps the work
the script has to do down to a minimum (some of our older Mac's have
enough trouble with some of the newer software we're running on them as
it is). I've also added some logging, just to keep track of when it's
run (or tried to run; I'm living with the assumption that if it logs
then it worked, realizing how dangerous assumptions can be. In this
case, it's an in-house script with very low priority and I have all the
time in the world to test it. Talk about no pressure! ;-)
tell application "System Events"
--First, check to see if Mail is running and quit it if it is
if exists application process "Mail" then
tell application "Mail" to quit
end if
--Here, we make sure we wait until the Mail.app has completely quit ...
repeat
delay 2
if not (exists application process "Mail") then exit repeat
end repeat
end tell
--Next, it's time to restart Mail!
tell application "Mail" to activate
--log activity for debugging purposes ...
--Create the text to output to the log file
set theOutput to "Mail app was restarted at " & (current date) & return
--Open the log file for writing
set theLogFile to open for access file ":Library:Scripts:Mail
Scripts:RestartMailLog.log" with write permission
--We need to know where the end of file is, so we can append to the file
set endOfFile to get eof of theLogFile
--Append to the file (DO IT!!!)
write theOutput to theLogFile as string starting at (endOfFile + 1)
--Close the file
close access theLogFile
By the way, I think I saw something from JD in the archives asking
someone why they were doing (eof + 1). In my case, without the +1 added
I lose the last character in the file. I did try the suggestion JD
offered in that mailing, but it over-wrote the entire file each time it
was run. Maybe I'm to green to see why (to date, AS is the only
language that leaves me feeling lost and scared, admittedly due to my
C/Java background), but the upshot is I wanted to append to the end of
the file and that suggestion didn't do that for me. So, I have this
hackish feeling (endOfFile + 1).
Ugly? Yes.
Wart-covered? Yes.
Beat to a pulp by the biggest ugly stick in all existence? Yes.
Functional? Yes ...
Tonight is the first real test of the system (crontab plus script; the
script works perfectly so far), but as usual any suggestions for
improvement will be met with great hostility (just kidding, in fact it
would be appreciated!)
PS: Although this obviously wasn't a real scripting project, I have
already started to like Smile a whole lot. Thanks Emmanuel!
PPS: I don't suppose anyone has an idea how to pass commands through
the Terminal.app to a process which has been telnetted to. We're using
Terminal to telnet to one of our servers which is running a business
program (FACTS 7.1 from Aperum, formerly Software Solutions, on the web
at www.sofsol.com). In this capacity, Terminal is simply a terminal
emulator. I have a script to automate a process for us (transferring
products between stores), but this script needs to pass text through
the emulator to FACTS (entered at menu's and prompts) as well as
function keys (<F4> and <F3>, mostly). In my last experiment, Terminal
just couldn't do that so I had to script another emulator (DataComet in
our case, which has a SEND and EXECUTE command in it's dictionary for
these purposes). Because of this, there is one person in the company
who isn't using Terminal (he has to use DataComet because of my
script). Not a problem per se, but something I just don't like. I went
through roughly a year ago, if anyone's interested in the original
postings they should be findable in the archives ... just search for
"scripting terminal". If anyone knows something I don't, please feel
the freedom to educate me!
Dave Stewart
Aqua-flo Supply (Goleta)
email@hidden
A computer lets you make more mistakes faster than any invention in
human history with the possible exceptions of handguns and tequila.
_______________________________________________
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.