Export UCF and Decompress it without IDMLTools

From IDMLWiki

Jump to: navigation, search
Target environment
ItemRequire
OS Mac OS X 10.5.x 〜
Language Perl, AppleScript

The following script exports a IDML package using active document on InDesign CS4 and decompressed it without IDMLTools. It means this script works on a machine that doesn’t have development environment, perhaps.

A IDML file is outputed in the same folder with the .indd file. Then after making a new folder in the same folder, the script stores decompressed UCF files in the folder.

This script was done checking of operations on Leopard. I don’t recommend using on Tiger. I think that especially this script may not works on Tiger with Japanese system.

sample script

  1. #!/usr/bin/perl -w
  2. use strict;
  3. use utf8;
  4. use open ":utf8";
  5. use open ":std";
  6.  
  7. # Make osascripts.
  8. my $InD_path_osa = new_InD_path();
  9. my $export_osa   = new_export();
  10. my $package_osa  = new_package();
  11.  
  12. # Get a file path that is active document of InDesign.
  13. my ( $dir_path, $docu_name ) = get_active_document_path();
  14.  
  15. # Export a IDML package.
  16. my $IDML_name = $docu_name;
  17. $IDML_name =~ s/\.indd$/\.idml/;
  18. # If you want to export a IDML to another directory else, rewrite $dir_path.
  19. # Then, don’t forget that $dir_path is Mac path.
  20. # And a colon is needed on the end. exsample "HD:Users:your_name:Desktop:"
  21. # $dir_path = "HD:Users:your_name:Desktop:";.
  22. export_IDML( $dir_path, $IDML_name );
  23.  
  24. # Decompress the IDML package.
  25. decompress( $dir_path, $IDML_name );
  26.  
  27.  
  28. #-----------------------------------------------------------------------------
  29. sub get_active_document_path{
  30.   my $result = readpipe $InD_path_osa;
  31.   if( $? != 0 ){ die "error : the ". __LINE__. "th line of “$0.”\n" };
  32.  
  33.   utf8::decode($result);
  34.   chomp $result;
  35.   if ( $result eq 'missing value' ){
  36.     print "There isn’t even one document.";
  37.     exit;
  38.   }
  39.   my ( $the_path, $the_name ) = split /, /, $result;
  40.   return ( $the_path, $the_name );
  41. }
  42.  
  43. #-----------------------------------------------------------------------------
  44. sub export_IDML{
  45.   my ( $destination_path, $idml_name ) = @_;
  46.   my $idml_path = "$destination_path$idml_name";
  47.   my $result = readpipe "$export_osa '$idml_path'";
  48.   if( $? != 0 ){ die "error : the ". __LINE__. "th line of “$0.”\n" };
  49.  
  50.   utf8::decode($result);
  51.   chomp $result;
  52.   if ( $result ne 'true' ){
  53.     print "AppleScript error : export_IDML() $result\n";
  54.     exit;
  55.   }  
  56. }
  57.  
  58. #-----------------------------------------------------------------------------
  59. sub decompress{
  60.   my ( $idml_dir_path, $idml_name ) = @_;
  61.   my $idml_path = "$idml_dir_path$idml_name";
  62.   my ( $destination_path, $source_dir_name ) = ('', '');
  63.   my @ARGV_for_as;  
  64.  
  65.   $source_dir_name = $idml_name;
  66.   $source_dir_name =~ s/\.idml$//;
  67.   $destination_path = "$idml_dir_path$source_dir_name";
  68.  
  69.   push @ARGV_for_as, 'd';
  70.   push @ARGV_for_as, "'$idml_path'";
  71.   push @ARGV_for_as, "'$destination_path'";
  72.   $package_osa .= " @ARGV_for_as"; 
  73.  
  74.   my $result = readpipe "$package_osa";
  75.   if( $? != 0 ){ die "error : the ". __LINE__. "th line of “$0.”\n" };
  76.  
  77.   utf8::decode($result);
  78.   chomp $result;
  79.   if ( $result ne 'true' ){
  80.     print "AppleScript error : decompress() $result\n";
  81.     exit;
  82.   }  
  83. }
  84.  
  85. #-----------------------------------------------------------------------------
  86. # Make osascripts.
  87. #-----------------------------------------------------------------------------
  88. sub compress_osa{
  89.   my $source_ref = shift;
  90.   my $osascript = 'osascript ';
  91.   map{
  92.     s/^[\t ]*//g;
  93.     s/"/\\"/g;
  94.     $osascript .= ' -e "'. $_. '"';
  95.   } @$source_ref;
  96.   return $osascript;
  97. }
  98.  
  99. sub new_InD_path{
  100.   my @AS = <<"__EOD__" =~ m/(.*)\n/g;
  101.   on run ARGV
  102.     tell application "Adobe InDesign CS4"
  103.       if (count of document) = 0 then return missing value
  104.       set a_dir_path to (file path of active document) as Unicode text
  105.       set a_docu_name to (name of active document) as Unicode text
  106.     end tell
  107.     return {a_dir_path, a_docu_name}
  108.   end run
  109. __EOD__
  110.   return compress_osa( \@AS );
  111. }
  112.  
  113. sub new_export{
  114.   my @AS = <<"__EOD__" =~ m/(.*)\n/g;
  115.   on run ARGV
  116.     set idml_path to ARGV as Unicode text
  117.     tell application "Adobe InDesign CS4"
  118.       tell active document
  119.         export format InDesign markup to idml_path without showing options
  120.       end tell
  121.     end tell
  122.     return true
  123.   end run
  124. __EOD__
  125.   return compress_osa( \@AS );
  126. }
  127.  
  128. sub new_package{
  129.   my @AS = <<"__EOD__" =~ m/(.*)\n/g;
  130.   on run ARGV
  131.     set {operation_mode, source_path, destination_path} to {item 1 of ARGV, item 2 of ARGV, item 3 of ARGV}
  132.     tell application "Adobe InDesign CS4"
  133.       if operation_mode is "c" then
  134.         package UCF source folder source_path UCF file destination_path
  135.       else if operation_mode is "d" then
  136.         unpackage UCF UCF file source_path destination folder destination_path
  137.       else
  138.         return "The operation mode is wrong."
  139.       end if
  140.     end tell
  141.     return true
  142.   end run
  143. __EOD__
  144.   return compress_osa( \@AS );
  145. }


Author

PsychoCat 00:12, 10 March 2009 (UTC)




Personal tools