X
Xiong Changnian
My little utility-in-the-making will scan a folder full of backups and
move the oldest ones to the Trash. So I'd like to hope.
I'm doing fine right up to the point where I wish to make the actual
move. That is, I've identified the files I wish to Trash -- I have the
full path in the form preferred under Mac OS 9.
So, what next? The usual Perl resources are no help, of course; this
issue is all about the Mac way of doing things. I dug through the
specialized-for-Mac modules included in the MacPerl distro; none seem to
fit the bill -- I can't imagine why, I think I must be overlooking
something. I'm pretty much a Perl novice.
It seems risky to go shoving files around directly; that's not the Mac
way. Hey, what about AppleScript? And indeed, I've got a little gimmick
working, sort of:
my $script;
$script = <<END;
tell application "Finder"
move file ("$deadfile") to trash
end tell
END
MacPerl:
oAppleScript($script) #do the trash script
or die ("AppleScript failed: $! \n");
This really does work -- very slowly and only once. If I call it twice
in a row (with two different path/filenames for $deadfile), MacPerl
stalls, stalls, stalls and if I start randomly clicking the mouse, I
hear the little "ding" of a file hitting the Trash. Then, nothing, no
matter what I do -- until I force-quit MacPerl. Then I get the second
"ding". Sure enough, both files are Trashed. I never die.
It seems that MacPerl is hogging time. It tells the Finder and the
Finder gets the command; but then MacPerl doesn't give it any time in
which to act. Not clear why clicking around sometimes helps; perhaps
it's just enough to burp a handler and the Finder gets a little time on
the way out -- something like that.
But basically -- I think -- Finder is waiting to be given time, while
MacPerl is waiting for a return from MacPerl:
oAppleScript(). Does that
seem right?
For the record, it's Mac OS 9.2.2, MacPerl 5.6.1r2 and yes, I have other
Perl scripts working fine.
* * *
So, let's speak frankly. I expect a number of responses and I'd like to
pre-reply to some of them.
* I realize this looks a little off-topic for this newsgroup and I'm
sorry about that. I don't have the first idea where to go for help; I
see no "*.macperl" NG.
* I did RTFM. I R all TFM I could lay my hands on. I've searched high
and wide on the infobahn. A pointer to a resource that actually contains
a solution to my problem is probably *better* than the solution itself,
yes, thank you. I'll look there first, next time.
* It's probably better not to adapt solutions intended for other
platforms, such as direct deletion. We Mac folks expect files to be
moved to the Trash, not deleted instanter. Sometimes we poke around in
the Trash before emptying it.
* It's my Mac. Yes, it is old and wheezy and small children throw stones
at my car when I drive to the corner store. Sorry, but all solutions
that include buying a new Mac and/or installing OS X are out, for today.
Same for those that require me to buy a real computer.
Many thanks await my White Knight.
move the oldest ones to the Trash. So I'd like to hope.
I'm doing fine right up to the point where I wish to make the actual
move. That is, I've identified the files I wish to Trash -- I have the
full path in the form preferred under Mac OS 9.
So, what next? The usual Perl resources are no help, of course; this
issue is all about the Mac way of doing things. I dug through the
specialized-for-Mac modules included in the MacPerl distro; none seem to
fit the bill -- I can't imagine why, I think I must be overlooking
something. I'm pretty much a Perl novice.
It seems risky to go shoving files around directly; that's not the Mac
way. Hey, what about AppleScript? And indeed, I've got a little gimmick
working, sort of:
my $script;
$script = <<END;
tell application "Finder"
move file ("$deadfile") to trash
end tell
END
MacPerl:
or die ("AppleScript failed: $! \n");
This really does work -- very slowly and only once. If I call it twice
in a row (with two different path/filenames for $deadfile), MacPerl
stalls, stalls, stalls and if I start randomly clicking the mouse, I
hear the little "ding" of a file hitting the Trash. Then, nothing, no
matter what I do -- until I force-quit MacPerl. Then I get the second
"ding". Sure enough, both files are Trashed. I never die.
It seems that MacPerl is hogging time. It tells the Finder and the
Finder gets the command; but then MacPerl doesn't give it any time in
which to act. Not clear why clicking around sometimes helps; perhaps
it's just enough to burp a handler and the Finder gets a little time on
the way out -- something like that.
But basically -- I think -- Finder is waiting to be given time, while
MacPerl is waiting for a return from MacPerl:
seem right?
For the record, it's Mac OS 9.2.2, MacPerl 5.6.1r2 and yes, I have other
Perl scripts working fine.
* * *
So, let's speak frankly. I expect a number of responses and I'd like to
pre-reply to some of them.
* I realize this looks a little off-topic for this newsgroup and I'm
sorry about that. I don't have the first idea where to go for help; I
see no "*.macperl" NG.
* I did RTFM. I R all TFM I could lay my hands on. I've searched high
and wide on the infobahn. A pointer to a resource that actually contains
a solution to my problem is probably *better* than the solution itself,
yes, thank you. I'll look there first, next time.
* It's probably better not to adapt solutions intended for other
platforms, such as direct deletion. We Mac folks expect files to be
moved to the Trash, not deleted instanter. Sometimes we poke around in
the Trash before emptying it.
* It's my Mac. Yes, it is old and wheezy and small children throw stones
at my car when I drive to the corner store. Sorry, but all solutions
that include buying a new Mac and/or installing OS X are out, for today.
Same for those that require me to buy a real computer.
Many thanks await my White Knight.