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

Opening a document in photoshop and running a ps script

New Here ,
Sep 24, 2008 Sep 24, 2008
I'm trying to write a script which will open a link in photoshop (which I have managed to do with Link.editOriginal) and also run a photoshop script after the file is opened. I have looked in online references and the PDF's found on this site, but I can't seem to find a function which will let me run a ps script from inside Indesign. Is there any method of doing this, or am I out of luck?

Thanks for your time.
TOPICS
Scripting
959
Translate
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
Community Expert ,
Sep 24, 2008 Sep 24, 2008
Which OS and which type of script is it (JS, VB, AScript)?
Translate
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
New Here ,
Sep 25, 2008 Sep 25, 2008
The OS is XP and I'm writing it in JS.

Thanks.
Translate
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
People's Champ ,
Sep 25, 2008 Sep 25, 2008
I tried this but didn't work so good :
var myscript = File("/c/.../myscript.jx");
myscript.execute();

the script is :
#target photoshop
alert("hey !");

in fact it seems that the file is launched but i am stuck with a confirm dialog and can't success passing over it so it's all automatic.
Translate
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
Community Expert ,
Sep 25, 2008 Sep 25, 2008
I was going to suggest using the File.execute function, but it will only work with VBS, I think.

In your case you might be able to use a tool I developed. Contact me by email (click on my username for the address) for more info.
Translate
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
People's Champ ,
Sep 26, 2008 Sep 26, 2008
i but it will only work with VBS, I think.

It runs very well in JS except...it's just that as it's ordered to run into photoshop, Windows try to warn against scripts that try to do things by their own.
It's like windows wanted to be certain it's not a virus and then wants you validate.

But that said, it breaks the automation process. That is what stucks me so far.

But I am certain someone here has the key.
Loic
Translate
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
Valorous Hero ,
Sep 26, 2008 Sep 26, 2008
May be this will help you this function is called from an ID script and sends a PS script (which resizes an image) via BridgeTalk message to PS.

Kasyan
//----------------------------
function ResizeInPS(myPath, myHorScale, myVerScale, myResolution, myResampleMethod) {

var bt = new BridgeTalk;
bt.target = "photoshop";
var myScript = 'try {\n';
myScript += 'var myPsDoc = app.open(File(\"' + myPath + '\"));\n';
myScript += 'app.preferences.rulerUnits = Units.PERCENT; \n' ;
myScript += 'myPsDoc.resizeImage(' + myHorScale +', ' + myVerScale + ', ' + myResolution + ', ' + myResampleMethod + '); \n' ;
myScript += 'myPsDoc.close(SaveOptions.SAVECHANGES);\n';
myScript += '}\n';
myScript += 'catch (myError) {\n';
myScript += 'myPsError += \"myError' + myPath + '\";\n';
myScript += '}';
bt.body = myScript;
bt.send();
}
Translate
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
Community Expert ,
Oct 14, 2008 Oct 14, 2008
Kasyan, great Script, seems to be just what I was looking for.
Translate
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
Contributor ,
Oct 15, 2008 Oct 15, 2008
Kasyan,

great function indeed.

I have tried to put it into a script to resize every link of a document.

But the script seems to be too quick!
The script below seems to update links that haven't been resized and while Photoshop is still working.

Is it possible to pause the script until the job in photoshop is completely done?


// resizeInPS.jsx
//DESCRIPTION: Resizes every link in PhotoShop
var theScale = 90; // scaling factor in %
var theResolution = 300;
var theResampleMethod = 'ResampleMethod.BICUBIC';

var myLinks = app.activeDocument.links;
for ( i = 0; i < myLinks.length; i++ )
{
ResizeInPS( myLinks.filePath, theScale, theScale, theResolution, theResampleMethod );
myLinks.update();
myLinks.parent.fit( FitOptions.FRAME_TO_CONTENT );
}

function ResizeInPS(myPath, myHorScale, myVerScale, myResolution, myResampleMethod) {
var bt = new BridgeTalk;
bt.target = "photoshop";
var myScript = 'try {\n';
myScript += 'var myPsDoc = app.open(File(\"' + myPath + '\"));\n';
myScript += 'app.preferences.rulerUnits = Units.PERCENT; \n' ;
myScript += 'myPsDoc.resizeImage(' + myHorScale +', ' + myVerScale + ', ' + myResolution + ', ' + myResampleMethod + '); \n' ;
myScript += 'myPsDoc.close(SaveOptions.SAVECHANGES);\n';
myScript += '}\n';
myScript += 'catch (myError) {\n';
myScript += 'myPsError += \"myError' + myPath + '\";\n';
myScript += '}';
bt.body = myScript;
bt.send();
}


Martin
Translate
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
Explorer ,
Oct 15, 2008 Oct 15, 2008
LATEST
> Is it possible to pause the script until the job in photoshop is completely done?

Instead of
bt.send()

do
bt.send(60); // wait for (at most) 60 seconds

This forces the sender of the message to wait/block until the receiver has
completed processing. You should have the receiver send a response so that the
caller can verify that the message has been processed; there doesn't appear to
be any type of timeout mechanism or exception in place if the processing takes
long than indicated.

-X
Translate
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
Contributor ,
Oct 15, 2008 Oct 15, 2008
Gerald Singelman told me to check the status of a link in a loop before executing the update()-command.

This is the updated version:

// resizeInPS04.jsx
//DESCRIPTION: Resizes every link in PhotoShop
var theScale = 150; // scaling factor in %
var theResolution = 72;
var theResampleMethod = 'ResampleMethod.BICUBIC';

var myChoice = confirm ('Warnung! \rBei Ausfühurng dieses Skriptes werden unwiderruflich alle verknüpften Bild-Dateien verändert. Machen Sie vorher Backups der Dateien.' );
if (myChoice == false)
exit();

var myLinks = app.activeDocument.links;
for ( var i = myLinks.length-1; i >= 0; i-- )
ResizeInPS( myLinks.filePath, theScale, theScale, theResolution, theResampleMethod );

while (myLinks[0].status == LinkStatus.NORMAL )
{
// think about the weather
}

myLinks.everyItem().update();

for ( var x = myLinks.length-1; x >= 0; x-- )
myLinks.parent.fit( FitOptions.FRAME_TO_CONTENT );

function ResizeInPS(myPath, myHorScale, myVerScale, myResolution, myResampleMethod) {
var bt = new BridgeTalk;
bt.target = "photoshop";
var myScript = 'try {\n';
myScript += 'var myPsDoc = app.open(File(\"' + myPath + '\"));\n';
myScript += 'app.preferences.rulerUnits = Units.PERCENT; \n' ;
myScript += 'myPsDoc.resizeImage(' + myHorScale +', ' + myVerScale + ', ' + myResolution + ', ' + myResampleMethod + '); \n' ;
myScript += 'myPsDoc.close(SaveOptions.SAVECHANGES);\n';
myScript += '}\n';
myScript += 'catch (myError) {\n';
myScript += 'myPsError += \"myError' + myPath + '\";\n';
myScript += '}';
bt.body = myScript;
bt.send();
}


Martin
Translate
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
Valorous Hero ,
Oct 15, 2008 Oct 15, 2008
Hi Martin,

This is just a small snippet from my script that resizes raster images (currently PSD and TIF, because we dont use other raster formats) and sets them to exactly 100% not like InDesign does: something like 99,89690721649485 or 101,13871724045462 (I dont know why but this annoys me). Im translating it from AS to JS.
If you are interested, I can post/send you an unfinished, intermediate version (no need to reinvent the wheel for you). And when I finish it, I am sure to post it for everybody who wants it.

Kasyan
Translate
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
Contributor ,
Oct 15, 2008 Oct 15, 2008
Hi Kasyan,

thank you for your offer to post me an unfinished version.

I am afraid that I would try to complete it by myself.
And there is less time to do this. ;-)

So I am looking forward to the finished version for every one.

I have published my short version in a german forum.
And I am sure, that many readers will be thankfull to get your code.

Thanks
Martin
Translate
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
Community Expert ,
Oct 15, 2008 Oct 15, 2008
Kasyan, that would be awesome.
Translate
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