Changeset 179
- Timestamp:
- 02/27/06 01:56:47
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/plagger/lib/Plagger/Plugin/Publish/Spotlight.pm
r173 r179 5 5 use Encode; 6 6 use File::Spec; 7 8 sub 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 } 7 16 8 17 sub register { … … 28 37 29 38 my $body = $self->templatize($context, $entry); 30 39 31 40 open my $out, ">:utf8", $path or $context->error("$path: $!"); 32 41 print $out $body; … … 34 43 35 44 # 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}) { 38 46 my $comment = $entry->body_text; 39 47 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 53 sub add_comment { 54 my($self, $path, $comment) = @_; 55 56 if ($self->{has_macglue}) { 42 57 my $finder = Mac::Glue->new("Finder"); 43 58 my $file = $finder->obj(file => $path); 44 59 $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: $!"); 46 67 } 47 68
