Export UCF and Decompress it without IDMLTools
From IDMLWiki
| Item | Require |
|---|---|
| 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
#!/usr/bin/perl -wuse strict;
use utf8;
use open ":utf8";
use open ":std";
# Make osascripts.my $InD_path_osa = new_InD_path();
my $export_osa = new_export();
my $package_osa = new_package();
# Get a file path that is active document of InDesign.my ( $dir_path, $docu_name ) = get_active_document_path();
# Export a IDML package.my $IDML_name = $docu_name;
$IDML_name =~ s/\.indd$/\.idml/;
# If you want to export a IDML to another directory else, rewrite $dir_path.# Then, don’t forget that $dir_path is Mac path.# And a colon is needed on the end. exsample "HD:Users:your_name:Desktop:"# $dir_path = "HD:Users:your_name:Desktop:";.export_IDML( $dir_path, $IDML_name );
# Decompress the IDML package.decompress( $dir_path, $IDML_name );
#-----------------------------------------------------------------------------sub get_active_document_path{
my $result = readpipe $InD_path_osa;
if( $? != 0 ){ die "error : the ". __LINE__. "th line of “$0.”\n" };
utf8::decode($result);
chomp $result;
if ( $result eq 'missing value' ){
print "There isn’t even one document.";
exit;
}my ( $the_path, $the_name ) = split /, /, $result;
return ( $the_path, $the_name );
}#-----------------------------------------------------------------------------sub export_IDML{
my ( $destination_path, $idml_name ) = @_;
my $idml_path = "$destination_path$idml_name";
my $result = readpipe "$export_osa '$idml_path'";
if( $? != 0 ){ die "error : the ". __LINE__. "th line of “$0.”\n" };
utf8::decode($result);
chomp $result;
if ( $result ne 'true' ){
print "AppleScript error : export_IDML() $result\n";
exit;
}}#-----------------------------------------------------------------------------sub decompress{
my ( $idml_dir_path, $idml_name ) = @_;
my $idml_path = "$idml_dir_path$idml_name";
my ( $destination_path, $source_dir_name ) = ('', '');
my @ARGV_for_as;
$source_dir_name = $idml_name;
$source_dir_name =~ s/\.idml$//;
$destination_path = "$idml_dir_path$source_dir_name";
push @ARGV_for_as, 'd';
push @ARGV_for_as, "'$idml_path'";
push @ARGV_for_as, "'$destination_path'";
$package_osa .= " @ARGV_for_as";
my $result = readpipe "$package_osa";
if( $? != 0 ){ die "error : the ". __LINE__. "th line of “$0.”\n" };
utf8::decode($result);
chomp $result;
if ( $result ne 'true' ){
print "AppleScript error : decompress() $result\n";
exit;
}}#-----------------------------------------------------------------------------# Make osascripts.#-----------------------------------------------------------------------------sub compress_osa{
my $source_ref = shift;
my $osascript = 'osascript ';
map{
s/^[\t ]*//g;
s/"/\\"/g;
$osascript .= ' -e "'. $_. '"';
} @$source_ref;
return $osascript;
}sub new_InD_path{
my @AS = <<"__EOD__" =~ m/(.*)\n/g;
on run ARGV
tell application "Adobe InDesign CS4"
if (count of document) = 0 then return missing value
set a_dir_path to (file path of active document) as Unicode text
set a_docu_name to (name of active document) as Unicode text
end tellreturn {a_dir_path, a_docu_name}
end run
__EOD__
return compress_osa( \@AS );
}sub new_export{
my @AS = <<"__EOD__" =~ m/(.*)\n/g;
on run ARGV
set idml_path to ARGV as Unicode text
tell application "Adobe InDesign CS4"
tell active documentexport format InDesign markup to idml_path without showing optionsend tellend tellreturn trueend run
__EOD__
return compress_osa( \@AS );
}sub new_package{
my @AS = <<"__EOD__" =~ m/(.*)\n/g;
on run ARGV
set {operation_mode, source_path, destination_path} to {item 1 of ARGV, item 2 of ARGV, item 3 of ARGV}
tell application "Adobe InDesign CS4"
if operation_mode is "c" then
package UCF source folder source_path UCF file destination_pathelse if operation_mode is "d" then
unpackage UCF UCF file source_path destination folder destination_path
elsereturn "The operation mode is wrong."
end ifend tellreturn trueend run
__EOD__
return compress_osa( \@AS );
}
Author
PsychoCat 00:12, 10 March 2009 (UTC)
