June 2003 Archives
You may or may not know about this little (hopefully largely unused) idiom:
perl -le '$FILE = ".bashrc"; open(FILE); print <FILE>'Since we don't use global variables anymore (right?), this is no longer useful. But wouldn't it be cool if that could work with lexicals? I offer no solution. Just the thought.
I updated happening to also show what the current window is in the frontmost app (if you have a glue created for it), and special-cased it for Terminal and ircle to show what process is running or what channel I am in (though the ircle one is disabled ... gotta have some privacy :-). One might also want to special-case iChat for similar reason, or any other app, just by making an additional subroutine for it.
I also fixed some little bugs and cleaned it up a little. Thanks to gnat for some ideas etc.
I also fixed some little bugs and cleaned it up a little. Thanks to gnat for some ideas etc.
So I've put together a script to update my iChat status, and it has evolved over time. It used to work with iChatStatus, but now iChat AV is scriptable, so I can update the status message from Mac::Glue.
The script I use now is called happening, and it forks itself into the background (startup of Mac::Carbon stuff is still pretty slow and processor-intensive in dyld, so it stays running all the time ... besides, I set it to run every 15 seconds anyway), and then runs through a series of checks on each loop.
It first looks to see if I am watching EyeTV locally, then looks to see if I am listening to an MP3 in iTunes. Then it calls another machine, executing a similar script, to see if that machine is running EyeTV or iTunes (right now this is done via ssh, but I am going to rewrite that remote script to also be a daemon, and have it write out a file I can check via HTTP; much more efficient).
If all those fail, it shows the current app, and if somehow that fails, it puts up something from fortune(6).
It makes heavy use of Mac::Glue to talk to iChat, iTunes, EyeTV, and System Events. It's super sweet! Note how it caches objects it is going to reuse ... makes it super fast and efficient, too. There are a bunch of me-specific things hardcoded in it ... sorry if that gets in your way. :-)
Here are the key lines for talking to iChat:
The script I use now is called happening, and it forks itself into the background (startup of Mac::Carbon stuff is still pretty slow and processor-intensive in dyld, so it stays running all the time
It first looks to see if I am watching EyeTV locally, then looks to see if I am listening to an MP3 in iTunes. Then it calls another machine, executing a similar script, to see if that machine is running EyeTV or iTunes (right now this is done via ssh, but I am going to rewrite that remote script to also be a daemon, and have it write out a file I can check via HTTP; much more efficient).
If all those fail, it shows the current app, and if somehow that fails, it puts up something from fortune(6).
It makes heavy use of Mac::Glue to talk to iChat, iTunes, EyeTV, and System Events. It's super sweet! Note how it caches objects it is going to reuse
Here are the key lines for talking to iChat:
$status = $ichat->prop('status');
return unless $status->get eq 'available';
$message = $ichat->prop('status message');
$message->set(to => $output);
Mac-OSA-Simple-1.05 has been released. Download it from the CPAN or SF.net.
(Note: it may take time for the release to propagate to the various download mirrors.)
Changes:
(Note: it may take time for the release to propagate to the various download mirrors.)
Changes:
* v1.04, Monday, April 21, 2003Posted using release by brian d foy.
Add support for saving/loading compiled AppleScripts as data in data fork
instead of resource in resource fork on Mac OS X, for compatability with
the Mac OS X Script Editor.
Mac-Carbon-0.53 has been released. Download it from the CPAN or SF.net.
(Note: it may take time for the release to propagate to the various download mirrors.)
Changes:
(Note: it may take time for the release to propagate to the various download mirrors.)
Changes:
* v0.53, 24 June 2003Posted using release by brian d foy.
OSADoEvent fixed
Fix some Files tests
Add Mac::Path::Util 0.09 to prereqs for Mac OS X
New iChat is scriptable. I have my "status message" setting script now bypassing iChatStatus altogether, and setting the status directly with Mac::Glue.
Now that iChat can stream audio/video from a DV camera, I could hook my DVD player up to my DV camera, play it back through the camera, and stream it over iChat. HA.
Now that iChat can stream audio/video from a DV camera, I could hook my DVD player up to my DV camera, play it back through the camera, and stream it over iChat. HA.
Now Playing: Old Enough To Know - Michael W. Smith (The Big Picture)
I am returned from "vacation," all moved into my new place in sunny northwest Washington. OK, not so sunny. I'll post more about it later when I am not so busy with being busy.
Now Playing: Don't Drink the Water - Dave Matthews Band (Before These Crowded Streets)
I get hundreds of spams per day, a large percentage of which are "virus spams," the Microsoft worms/viruses that try to infect my Mac. And a significant number of those are bounce messages telling me that the mail that "I sent" contained a virus. Except, of course, that I never sent that mail.
Can someone clue these people in, the ones that run these "helpful" systems, that it is likely that none of the virus spams they are getting actually come from the user in the From: address? They are contributing to the problem. They are not helping.
Can someone clue these people in, the ones that run these "helpful" systems, that it is likely that none of the virus spams they are getting actually come from the user in the From: address? They are contributing to the problem. They are not helping.
This works now (in my local code, I won't release it for a couple of weeks probably):
use Mac::OSA::Simple;Of course, you could load a compiled AppleScript from disk instead of compiling one in memory, but it is easier to demonstrate it like this.
my $script = compile_applescript(<<"EOS");
on \xC7event abcd1234\xC8 (trackname, foo)
tell application "iTunes"
play (first track of library playlist 1 whose name is trackname)
return [artist of current track, foo]
end tell
end \xC7event abcd1234\xC8
EOS
print join "|", $script->call('abcd', '1234', ["I Hung My Head", "garble!"]);
I've had several requests before to make OSA scripts accept arguments. For example, in Mac::OSA::Simple, you can do, for a saved script:
So I mostly have it worked out that you will be able to pass arguments to your compiled AppleScript. What the code will look like, with the AppleScript:
And yes, I know, Mac::Carbon is still slow when loading the extensions, in some cases. I'll work on that this summer, too. :-)
tell application "iTunes"This:
play
end tell
my $play = load_osa_script('itunes_play');But what if you want to play a specific track? You don't want to recompile your script, because that is inefficient (it can take awhile to compile an AppleScript, plus you don't want little AppleScripts all over the place).
$play->execute;
So I mostly have it worked out that you will be able to pass arguments to your compiled AppleScript. What the code will look like, with the AppleScript:
on «event abcd1234» (trackname)and the Perl code:
tell application "iTunes"
play (first track of library playlist 1 whose name is trackname)
end tell
end «event abcd1234»
my $play = load_osa_script('itunes_play');And on the command line or whatever, you could have simply:
$play->call('abcd ', '1234', 'Pearls Before Swine');
% iplay "Pearls Before Swine"That's the plan, anyway. I have it working (the low-level stuff). I found a bug in Mac::OSA::OSADoEvent where the reply event was not getting filled out, so it was failing, so it will require a newer Mac::Carbon. I'll do it sometime this summer.
And yes, I know, Mac::Carbon is still slow when loading the extensions, in some cases. I'll work on that this summer, too.
Now Playing: Most Likely You Go Your Way And I'll Go Mine - Bob Dylan (Biograph)