• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Modifying an old script from Dave Saunders

Guru ,
Oct 09, 2013 Oct 09, 2013

Copy link to clipboard

Copied

I've gotten permission from Dave Saunders to ask someone here to help modify a script he wrote way back when.

The script is posted at:

http://pdsassoc.com/downloads/PDFimportCropPref.jsx.zip

The purpose of the script is to change the Crop options of an already placed PDF (includes AI and INDD) file.

The script was written in 2006 for CS2 and so it doesn't work in today's environment.

I'm posting a copy of the text in the hope it doesn't get garbled.

//DESCRIPTION: Allows user to change PDF-import cropping preference

/*
©Copyright 2006 PDS Associates

This script must not be distributed without first obtaining written permission of:

Dave Saunders, proprietor
PDS Associates
P.O. Box 127
Allenhurst, NJ 07711-0127

e-mail: davesaunders@pdsassoc.com
*/

// Destroy any existing dialogs
if (app.dialogs.length > 0) app.dialogs.everyItem().destroy();
interactWithAll();
curSetting = app.pdfPlacePreferences.pdfCrop;
userChooses = askUser(curSetting);
app.pdfPlacePreferences.pdfCrop = userChooses

// +++++++ Functions Start Here +++++++++++++++++++++++

function interactWithAll() {
if (app.version == 3) {
app.userInteractionLevel = UserInteractionLevels.interactWithAll;
} else {
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
}
}

function askUser(curValue){
var cropChoices = ["Art", "Bleed", "Content", "Media", "PDF", "Trim"];
var cropValues = [1131573313, 1131573314, 1131573315, 1131573325, 1131573328, 1131573332];
cv = -1;
for (var j = cropValues.length – 1; j >= 0; j–) {
if (curValue == cropValues) {
cv = j;
continue
}
}
if (cv == -1) errorExit(“Current value of crop preference not recognized”);
with (app.dialogs.add({name:”Place PDF Crop Preference”})) {
with (dialogColumns.add()) {
with (dialogRows.add()) {
staticTexts.add({staticLabel:”Choose preference:”});
uchoose = dropdowns.add({stringList:cropChoices, selectedIndex:cv})
}
}
app.activate();
if (!show()) {
// User canceled;
destroy();
exit()
} else {
value = cropValues[uchoose.selectedIndex];
destroy();
}
return value
}
}

function errorExit(message) {
if (arguments.length > 0) {
if (app.version != 3) { beep() } // CS2 includes beep() function.
alert(message);
}
exit(); // CS exits with a beep; CS2 exits silently.
}

If you are interested in this challenge, your modified script will be mentioned at InDesignSecrets.com where we can link to your download page as well as extoll the brilliance of your scripting abilities. Sorry, no money, just glory.

Send me a message at Sandee at mac dot com if you want to tackle the script.

Thanks

TOPICS
Scripting

Views

3.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Oct 09, 2013 Oct 09, 2013

Copy link to clipboard

Copied

Okay I want glory

Let's try to make it short:

//====================================================================

// PDFImportCropPref Reloaded

// (should work in ID CS/CS2/CS3/CS4/CS5/CS6/CC)

//====================================================================

(function(o,a,z,r,i,x,t,k)

{

    for(k in o) o.hasOwnProperty(k) &&

        (a['_'+z]=t=+o) &&

        (a[z++]=k.substr(5).replace(r,' ')) &&

        (i||(x==t&&(i=z)));

    (((k='userInteractionLevel')in(o=app))?o:o.scriptPreferences)

        = +UserInteractionLevels.interactWithAll;

    (t=o.dialogs).length && t.everyItem().destroy();

    r=(t=t.add({name:"Place PDF Crop Preference"}))

        .dialogColumns.add().dialogRows.add()

        .staticTexts.add({staticLabel:"Choose preference: "})

        .parent.dropdowns.add({stringList:a,selectedIndex:i-1});

    o.activate();

    t.show() && (o.pdfPlacePreferences.pdfCrop=a['_'+r.selectedIndex]);

})(PDFCrop,[],0,/_/g,0,+app.pdfPlacePreferences.pdfCrop);

@+

Marc

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Oct 09, 2013 Oct 09, 2013

Copy link to clipboard

Copied

Hi,

... end of competition ...

Jarek

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Oct 10, 2013 Oct 10, 2013

Copy link to clipboard

Copied

After CS4 there are changes in "Pdfcrop" enums list.

Instead of "CROP_CONTENT" new enums were introduced "CROP_CONTENT_ALL_LAYERS" and "CROP_CONTENT_VISIBLE_LAYERS". hence this script does not work in current versions of InDesign.

if you replace two lines:

     var cropChoices = ["Art", "Bleed", "Content", "Media", "PDF", "Trim"];

     var cropValues = [1131573313, 1131573314, 1131573315, 1131573325, 1131573328, 1131573332];

With these lines:

     var cropChoices = ["Art", "Bleed", "ContentAllLayers","ContentVisibleLayers", "Media", "PDF", "Trim"];

     var cropValues = [1131573313, 1131573314, 1131561324,1131566703, 1131573325, 1131573328, 1131573332];

It will be compatible with CS5 and later versions of InDesign.

Or, You can use @Marc script , that is more generic.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Oct 16, 2013 Oct 16, 2013

Copy link to clipboard

Copied

Thanks Marc and Sumgarg for helping Sandee. I've been in hospital for three weeks and am only now able to starting thinking again.

Dave

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Oct 17, 2013 Oct 17, 2013

Copy link to clipboard

Copied

LATEST

I wish you a quick & speedy recovery, Dave!

I’ve learned a lot from your posts, site and blog. Without people like you, I‘d never become a scripter. Thank you a lot!

Kasyan

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines