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

Can you specify the background color when resizing the canvas?

New Here ,
Feb 08, 2010 Feb 08, 2010

I haven't found this in the Scripting Reference.

In the "Canvas Size…" dialog box you can specify the "Canvas Extension Color" to "Foreground", Background", "White", "Black", "Grey" or "Other…".

Can this be scripted?

I am writing an AppleScript to resize my canvas in order to add a slug to the bottom of the image. Currently my script stores the background color, so I can change it to White to accomplish my goal without discarding the background color (which gets restores at the end of the script). The problem is that if the user has a custom color (i.e. Pantone color) as the background color, the color does not get stored.

TOPICS
Actions and scripting
3.3K
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
Adobe
Guru ,
Feb 08, 2010 Feb 08, 2010

You have to use scriptlistner to set the canvas color with expanding the canvas. See the scripting guide for using scriptlistner with AppleScript.

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 ,
Feb 08, 2010 Feb 08, 2010

Thank you for the quick response!

I don't think it will work for me because the scripting reference states that there is no AppleScript interface to the Action Manager.

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
Guru ,
Feb 08, 2010 Feb 08, 2010

As Mark pointed out, use the ScriptingListenerJS.log and then you can use AppleScript's do javascript command. Scriptlistner code in the JS log is really javascript even if it doen't look like it.

From the scripting guide...

There is no Action Manager functionality in AppleScript. However, you can execute JavaScript code and
files from AppleScript using the do javascript command.

If you don't want to much with saving, setting, then restoring the background color this is the best way.

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 ,
Feb 08, 2010 Feb 08, 2010

I have found that it defaults to the background colour, so all I do is set the background colour first before expanding the canvas.

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
Guru ,
Feb 08, 2010 Feb 08, 2010

If you wish to avoid the background color route you could possibly go the way of making your layer none background increase canvas then add solid fill white layer below last. This you can do with script listener via do javascript.

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
Guest
Feb 08, 2010 Feb 08, 2010

Yes, yet applescript can call javascripts from Scriptlistener and get access that way.   That is in the documentation.

Hope that helps

John Wheeler

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 ,
Feb 17, 2010 Feb 17, 2010
I have found that it defaults to the background colour, so all I do is set the background colour first before expanding the canvas.


Thanks Paul,

That is the way I was doing it. As I wrote in my original post, my script stores the background color so that it can be restored later. The probelm is if the user has a custom color set as the background color.

Yes, yet applescript can call javascripts from Scriptlistener and get access that way.   That is in the documentation.

Hope that helps

John Wheeler,

Thanks! I did see that. I would have to pass values to the java script in order to increase the canvas size appropriately. I really cannot make heads or tails out of the data that ScriptingListener puts out. It's not at all what AppleScript looks like.

If you wish to avoid the background color route you could possibly go the way of making your layer none background increase canvas then add solid fill white layer below last. This you can do with script listener via do javascript.
As Mark pointed out, use the ScriptingListenerJS.log and then you can use AppleScript's do javascript command. Scriptlistner code in the JS log is really javascript even if it doen't look like it.

Thanks Muppet Mark & Michael L Hale,

I am very surprised that this cannot be done in AppleScript.  It looks like my solution is to learn Java script.

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
Guru ,
Feb 17, 2010 Feb 17, 2010

See if this works for you… Just some very basic AppleScript with a call to 'do javascript' in this case the variable 'Solid_Fill' this is a cleaned up piece of scriptlistener output (done very nicely by X's tools you will see a post below to the latest release of this) The scriptlistener output has been turned into a function that javascript can call. Inside of the function call I have put a list arguments passed from AppleScript. So the values 0, 0, 0, 0 in the AppleScript list end up as arguments passed to the functions C, M, Y, K variables. AppleScript objects are 1 based Javascript are 0 based & values the same.

set Solid_Fill to "function solidFillCMYK(C, M, Y, K) {

function cTID(s) { return app.charIDToTypeID(s); };

function sTID(s) { return app.stringIDToTypeID(s); };

var desc8 = new ActionDescriptor();

var ref4 = new ActionReference();

ref4.putClass( sTID('contentLayer') );

desc8.putReference( cTID('null'), ref4 );

var desc9 = new ActionDescriptor();

var desc10 = new ActionDescriptor();

var desc11 = new ActionDescriptor();

desc11.putDouble( cTID('Cyn '), C );

desc11.putDouble( cTID('Mgnt'), M );

desc11.putDouble( cTID('Ylw '), Y );

desc11.putDouble( cTID('Blck'), K );

desc10.putObject( cTID('Clr '), cTID('CMYC'), desc11 );

desc9.putObject( cTID('Type'), sTID('solidColorLayer'), desc10 );

desc8.putObject( cTID('Usng'), sTID('contentLayer'), desc9 );

executeAction( cTID('Mk  '), desc8, DialogModes.NO );

}; solidFillCMYK(arguments[0], arguments[1], arguments[2], arguments[3]);"

tell application "Adobe Photoshop CS2"

activate

set User_Rulers to ruler units of settings

set ruler units of settings to pixel units

set Doc_Ref to the current document

tell Doc_Ref

set background layer of last layer to false

do javascript Solid_Fill with arguments {0, 0, 0, 0} show debugger on runtime error

move first layer to end

set Doc_Height to height

-- set Doc_Width to width did NOT need this

resize canvas height Doc_Height + 200 anchor position top center

flatten

end tell

set ruler units of settings to User_Rulers

end tell

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
Guru ,
Feb 17, 2010 Feb 17, 2010
LATEST

nonintuitive wrote:

I am very surprised that this cannot be done in AppleScript.  It looks like my solution is to learn Java script.

Just to be clear - you have to use scriptlistner to set the extension color even in Javascript. So even with Javascript you are going to have code that looks similar the the AppleScript Mark just posted.

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