Re: Script not quitting Entourage + debugging strategies
Re: Script not quitting Entourage + debugging strategies
- Subject: Re: Script not quitting Entourage + debugging strategies
- From: Charles Arthur <email@hidden>
- Date: Sun, 24 Dec 2000 14:40:52 +0000
On Fri, 22 Dec 2000 02:59:33 -0800 chris stearns <email@hidden> wrote:
>
The second tell block works just perfectly. (I just used the 'record'
>
feature on the Script Editor, as I'm sure you can see. Sure, it's ugly code,
>
but it's a newbie's dream. And it works.)
>
Trouble is, the script will NOT quit Entourage if it is running. I picked up
>
the 'currProcs' bit of the script on this list a week or so ago.
>
>
Any ideas? Here's the script:
>
>
>
---
>
tell application "Finder"
>
set currProcs to processes
>
end tell
>
if "Microsoft Entourage" is in currProcs then
>
tell application "Microsoft Entourage" to quit
>
end if
As others have pointed out, the question you're asking in the "if"
statement will always fail. The reason is that you're comparing a string
("Microsoft Entourage") with a list composed of process names. Not an
obvious one by any means.
I didn't know this was the problem until I tried it out, intrigued. My
recommendation though isn't about how to actually *do* this (others have
pointed out better ways) but about strategies for trapping bugs like this.
For instance, to see if you're ever actually getting past the "If" test,
put a line like "display dialog "true" giving up after 1" after the if
statement. Then it'll briefly flash a display which tells you you're going
in. You don't have to hit "OK" - the giving up after does that for you.
If that "true" dialog never appears, you've got a clue your "if" is
failing.
The "giving up after" is a debugger's lifesaver, I'd say. Use it often.
Then try putting something like a repeat loop which works through the
current processes:
repeat with i in the currProcs
display dialog i giving up after 1
if "Microsoft Entourage..." (etc)
..
end if
end repeat
This will flash up the current process. You'll see MS En flash up and
wonder why given that's the case that the "if" is still failing. Probably a
class mismatch, as you'll learn is often the case when these apparently
correct things fail.
Then try..
repeat with i in the currProcs
display dialog class of i
...
end repeat
This fails: "can't make process <name of your first process> into list,
string or text." Processes appear to be special things, rather like dates.
So you have to coerce the process name into a string so you can do the
"if..." comparison.
So:
repeat with i in the currProcs
set a to i as text
display dialog a giving up after 1
if a is "Microsoft Entourage" then....
which works. My only problem was that the "tell application to quit"
crashed my machine. Ah well.
By the way, the solution "tell application Finder to set currProcs to the
names of current processes" is far more elegant than my code above.
One last thing:
>
tell application "Finder"
>
select disk "OS X HD"
>
open selection
>
select folder "Microsoft User Data" of disk "OS X HD"
>
delete selection
>
close container window of disk "OS X HD"
>
select folder "Microsoft User Data" of folder "Documents" of disk
>
"Macintosh HD"
>
copy selection to disk "OS X HD"
>
end tell
Risky. You delete the thing and then put something in its place. (At least
you don't force-empty the trash). Better, if you could, to rename the
backup folder, thus keeping it in case your new one gets corrupted. Two
backups are better than one! And two backups *in different locations* even
better.
Charles, who has just spent far too long writing a script to
autobackup on demand to three different places.
http://www.ukclimbing.com : 1,000+ British crags, 350+ British climbing walls
- searchable by distance rock type, etc, with 5-day weather forecasts for
every one - plus maps, articles, news, and the New Routes database. There's
even a cool shop attached...