Changeset 179

Show
Ignore:
Timestamp:
02/27/06 01:56:47
Author:
miyagawa
Message:

Publish::Spotlight now checks if Mac::Glue is installed and fallbacks to osascript. Fixes #67

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plagger/lib/Plagger/Plugin/Publish/Spotlight.pm

    r173 r179  
    55use Encode; 
    66use File::Spec; 
     7 
     8sub init { 
     9    my $self = shift; 
     10    $self->SUPER::init(@_); 
     11 
     12    if ($self->conf->{add_comment}) { 
     13        $self->{has_macglue} = eval { require Mac::Glue; 1 }; 
     14    } 
     15} 
    716 
    817sub register { 
     
    2837 
    2938    my $body = $self->templatize($context, $entry); 
    30      
     39 
    3140    open my $out, ">:utf8", $path or $context->error("$path: $!"); 
    3241    print $out $body; 
     
    3443 
    3544    # Add $entry->body as spotlight comment using AppleScript (OSX only) 
    36     if ($self->{conf}->{add_comment}) { 
    37         eval { require Mac::Glue }; 
     45    if ($self->conf->{add_comment}) { 
    3846        my $comment = $entry->body_text; 
    3947        utf8::decode($comment) unless utf8::is_utf8($comment); 
    40         $comment = encode("shift_jis", $comment); # xxx 
    41          
     48        $comment = encode("shift_jis", $comment); # xxx UTF-16? 
     49        $self->add_comment($path, $comment); 
     50    } 
     51
     52 
     53sub add_comment { 
     54    my($self, $path, $comment) = @_; 
     55 
     56    if ($self->{has_macglue}) { 
    4257        my $finder = Mac::Glue->new("Finder"); 
    4358        my $file = $finder->obj(file => $path); 
    4459        $file->prop('comment')->set(to => $comment); 
    45     } 
     60    } else { 
     61        system( 
     62            'osascript', 
     63            'bin/spotlight_comment.scpt', 
     64            $path, 
     65            $comment, 
     66        ) == 0 or Plagger->context->error("$path: $!"); 
    4667} 
    4768