[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

(DTPtechNote:1345) Re: [DTP] DTP2.0



とりあえず、これを参考にしてください。
(バックスラッシュはどうなるかな?)
-----------------------
#!/usr/bin/perl

use strict;
use utf8;
use Encode qw/from_to/;

binmode(STDOUT, ":utf8");
binmode(STDIN, ":utf8");
binmode(STDERR, ":utf8");

my $posixPath = '/Users/hogehoge/ドキュメント/Personal:Data';
my $macPath = posix2macPath($posixPath);
print "--> $macPath?n";

sub posix2macPath{
  my $aPath = shift;
  my $result;
  my $command = 'osascript';

  $command .= ' -e "set posixPath to ?"'. $aPath. '?" as Unicode text"';
  $command .= ' -e "set macPath to POSIX file posixPath"';

#-- debug
  $command .= ' -e "tell application ?"Finder?""';
  $command .= ' -e "activate"';
  $command .= ' -e "display dialog macPath as string"';
  $command .= ' -e "end tell" ';
#--
  
  $command .= ' -e "return macPath as string"';

  utf8::encode($command);
  from_to($command, 'utf8', 'shiftjis');
  $result = readpipe $command;
  utf8::decode($result);

  chop $result;
  $result =~ s/^file //;
  return $result;
}
-----------------------