Export UCF and Decompress it without IDMLTools/ja

From IDMLWiki

Jump to: navigation, search

IDMLToolsを使わずに UCFをエクスポートし、解凍する

記事内容の対象環境
項目条件
OS Mac OS X 10.5.x 〜
言語 Perl, AppleScript

次のスクリプトはIDMLToolsを使わずに Mac上で実行できます。最前面にある CS4のドキュメントからIDMLパッケージをエクスポートした後、ZIPファイルを解凍します。つまり、開発環境のない(Developer tool をインストールしていない) Mac上でも動作します。たぶん。

InDesignのドキュメントと同じフォルダーに出力されます。そして、ドキュメントと同じ名前(拡張子を除いた名前)の新しいフォルダが作成され、そこに UCF files が解凍されます。

このスクリプトは Leopard で動作確認しています。Tigerは推奨しません。日本語環境で Tigerが稼働している時は動かないかもしれません。


Note Note: そもそも、IDMLを大部分理解した後は IDMLToolsは必要ないかもしれません。すべての仕事は自分が一番慣れ親しんだ開発環境で IDMLの業務はこなせるはずです。IDMLToolsをインストールした後に環境設定が必要ですが、これらはJavaのサンプルコード実行のためであり、Javaを要求しているのも Windows/Macのプログラマーに対して、同一のソースコードでサンプルを提供するためでしょう。たぶんね


sample script

  1. #!/usr/bin/perl -w
  2. use strict;
  3. use utf8;
  4. use open ":utf8";
  5. use open ":std";
  6.  
  7. # osascriptの準備。
  8. my $InD_path_osa = new_InD_path();
  9. my $export_osa   = new_export();
  10. my $package_osa  = new_package();
  11.  
  12. # 最前面にある InDesignのドキュメントのファイルパスを得る。
  13. my ( $dir_path, $docu_name ) = get_active_document_path();
  14.  
  15. # IDMLパッケージをエクスポートする。
  16. my $IDML_name = $docu_name;
  17. $IDML_name =~ s/\.indd$/\.idml/;
  18.  
  19. # もし、IDMLを別のフォルダーにエクスポートしたかったら、$dir_path を書き直してください。
  20. # そのとき、$dir_path は Macパスを記述することを忘れないでください。Posix path ではありません。
  21. # パスの最後に コロン も忘れないように。例えば、"HD:Users:your_name:Desktop:"
  22. # $dir_path = "HD:Users:your_name:Desktop:";
  23. export_IDML( $dir_path, $IDML_name );
  24.  
  25. # IDMLパッケージを解凍する。
  26. decompress( $dir_path, $IDML_name );
  27.  
  28.  
  29. #-----------------------------------------------------------------------------
  30. sub get_active_document_path{
  31.   my $result = readpipe $InD_path_osa;
  32.   if( $? != 0 ){ die "error : the ". __LINE__. "th line of “$0.”\n" };
  33.  
  34.   utf8::decode($result);
  35.   chomp $result;
  36.   if ( $result eq 'missing value' ){
  37.     print "There isn’t even one document.";
  38.     exit;
  39.   }
  40.   my ( $the_path, $the_name ) = split /, /, $result;
  41.   return ( $the_path, $the_name );
  42. }
  43.  
  44. #-----------------------------------------------------------------------------
  45. sub export_IDML{
  46.   my ( $destination_path, $idml_name ) = @_;
  47.   my $idml_path = "$destination_path$idml_name";
  48.   my $result = readpipe "$export_osa '$idml_path'";
  49.   if( $? != 0 ){ die "error : the ". __LINE__. "th line of “$0.”\n" };
  50.  
  51.   utf8::decode($result);
  52.   chomp $result;
  53.   if ( $result ne 'true' ){
  54.     print "AppleScript error : export_IDML() $result\n";
  55.     exit;
  56.   }  
  57. }
  58.  
  59. #-----------------------------------------------------------------------------
  60. sub decompress{
  61.   my ( $idml_dir_path, $idml_name ) = @_;
  62.   my $idml_path = "$idml_dir_path$idml_name";
  63.   my ( $destination_path, $source_dir_name ) = ('', '');
  64.   my @ARGV_for_as;  
  65.  
  66.   $source_dir_name = $idml_name;
  67.   $source_dir_name =~ s/\.idml$//;
  68.   $destination_path = "$idml_dir_path$source_dir_name";
  69.  
  70.   push @ARGV_for_as, 'd';
  71.   push @ARGV_for_as, "'$idml_path'";
  72.   push @ARGV_for_as, "'$destination_path'";
  73.   $package_osa .= " @ARGV_for_as"; 
  74.  
  75.   my $result = readpipe "$package_osa";
  76.   if( $? != 0 ){ die "error : the ". __LINE__. "th line of “$0.”\n" };
  77.  
  78.   utf8::decode($result);
  79.   chomp $result;
  80.   if ( $result ne 'true' ){
  81.     print "AppleScript error : decompress() $result\n";
  82.     exit;
  83.   }  
  84. }
  85.  
  86. #-----------------------------------------------------------------------------
  87. # Make osascripts.
  88. #-----------------------------------------------------------------------------
  89. sub compress_osa{
  90.   my $source_ref = shift;
  91.   my $osascript = 'osascript ';
  92.   map{
  93.     s/^[\t ]*//g;
  94.     s/"/\\"/g;
  95.     $osascript .= ' -e "'. $_. '"';
  96.   } @$source_ref;
  97.   return $osascript;
  98. }
  99.  
  100. sub new_InD_path{
  101.   my @AS = <<"__EOD__" =~ m/(.*)\n/g;
  102.   on run ARGV
  103.     tell application "Adobe InDesign CS4"
  104.       if (count of document) = 0 then return missing value
  105.       set a_dir_path to (file path of active document) as Unicode text
  106.       set a_docu_name to (name of active document) as Unicode text
  107.     end tell
  108.     return {a_dir_path, a_docu_name}
  109.   end run
  110. __EOD__
  111.   return compress_osa( \@AS );
  112. }
  113.  
  114. sub new_export{
  115.   my @AS = <<"__EOD__" =~ m/(.*)\n/g;
  116.   on run ARGV
  117.     set idml_path to ARGV as Unicode text
  118.     tell application "Adobe InDesign CS4"
  119.       tell active document
  120.         export format InDesign markup to idml_path without showing options
  121.       end tell
  122.     end tell
  123.     return true
  124.   end run
  125. __EOD__
  126.   return compress_osa( \@AS );
  127. }
  128.  
  129. sub new_package{
  130.   my @AS = <<"__EOD__" =~ m/(.*)\n/g;
  131.   on run ARGV
  132.     set {operation_mode, source_path, destination_path} to {item 1 of ARGV, item 2 of ARGV, item 3 of ARGV}
  133.     tell application "Adobe InDesign CS4"
  134.       if operation_mode is "c" then
  135.         package UCF source folder source_path UCF file destination_path
  136.       else if operation_mode is "d" then
  137.         unpackage UCF UCF file source_path destination folder destination_path
  138.       else
  139.         return "The operation mode is wrong."
  140.       end if
  141.     end tell
  142.     return true
  143.   end run
  144. __EOD__
  145.   return compress_osa( \@AS );
  146. }


執筆者

PsychoCat 00:12, 10 March 2009 (UTC)



Personal tools