Run applescript from within photoshop script?

Discussion of Photoshop Scripting, Photoshop Actions and Photoshop Automation in General

Moderators: Tom, Kukurykus

Mcquiff

Run applescript from within photoshop script?

Post by Mcquiff »

Is this possible, All I would like to do is get the path of the open file and then turn the label to red to indicate that it has been completed,

I would use my existing saving script

Code: Select allfunction saveAS() {
if(!documents.length) return;
activeDocument.info.captionWriter = "Editted_by_Photographer";
if(activeDocument.layers.length > 1){
var desc2 = new ActionDescriptor();
var desc3 = new ActionDescriptor();
desc3.putBoolean( stringIDToTypeID('maximizeCompatibility'), true );
desc2.putObject( charIDToTypeID('As  '), charIDToTypeID('Pht3'), desc3 );
try{executeAction( charIDToTypeID('save'), desc2, DialogModes.ALL );}catch(e){}
}else{
try{executeAction( charIDToTypeID('save'), undefined, DialogModes.ALL );}catch(e){}
}
};

saveAS();
Mcquiff

Run applescript from within photoshop script?

Post by Mcquiff »

I would aim to run something like this.

Code: Select alltell application id "com.adobe.Photoshop"
   set theDocument to document 1
   set theFilePath to file path of theDocument
   
end tell

tell application "Finder"
   set label index of document file theFilePath to 6
end tell
Mcquiff

Run applescript from within photoshop script?

Post by Mcquiff »

I've saved the applescript as an app can i run it from there?
larsen67

Run applescript from within photoshop script?

Post by larsen67 »

You can call osa script using app.system() to do this…

#target photoshop

var docPath = app.activeDocument.fullName;

setFinderLabel( docPath, 2);

function setFinderLabel( fileObj, numb ) {
var sh = 'osascript -e \'Tell application "Finder"';
sh += ' to set label index of ((POSIX file "';
sh += fileObj.fsName;
sh += '") as alias) to ' + numb.toString() + '\'';
var res = app.system( sh );
res == 0 ? res = true : res = false;
return res;
};

Play with the numbers you pass as they are still out of expected order… but work just fine…

You should also check/test the file has a valid path/is saved already…
Mcquiff

Run applescript from within photoshop script?

Post by Mcquiff »

That works a treat! Thanks

Now I am using it I need to add a condition.

That is if the file is in a dropbox folder then make label red, else do nothing.

You should also check/test the file has a valid path/is saved already…
Also I will need to check if it saved already, else again do nothing,

Code: Select alltell application id "com.adobe.Photoshop"
   set theDocument to the current document
   set theFilePath to file path of theDocument
   set theFilePathtext to theFilePath as text
end tell

tell application "Finder"
   if theFilePathtext contains "Dropbox" then
      set label index of document file theFilePath to 2
   end if
end tell

I've been trying this


Code: Select all#target photoshop

var docPath = app.activeDocument.fullName;

setFinderLabel( docPath, 2);

function setFinderLabel( fileObj, numb ) {
var sh = 'osascript -e \'Tell application "Finder"';
sh += 'if ((POSIX file "';
sh += fileObj.fsName;
sh += '") as text contains "Dropbox" then';
sh += ' set label index of ((POSIX file "';
sh += fileObj.fsName;
sh += '") as alias) to ' + numb.toString() + '\'';
sh += ' end if'
sh += ' end tell'
var res = app.system( sh );
res == 0 ? res = true : res = false;
return res;
};