Skip to main content
March 2, 2010
Answered

Clear Slices

  • March 2, 2010
  • 1 reply
  • 4856 views

Hello,

How to call the "Clear Slices" function of the View menu in an AppleScript?

Thomas

This topic has been closed for replies.
Correct answer Muppet Mark

Mike, I can neither play back a recorded action via the GUI pallet or use Applescripts do action "X" from "Z" both create and app dialog about not being available.


Strangely enough it works fine using system events GUI scripting but thats a very low level way about the problem.

tell application "Adobe Photoshop CS2"

activate

if exists current document then

my Clear_Slices()

end if

end tell

on Clear_Slices()

tell application "System Events"

tell application process "Adobe Photoshop CS2"

tell menu bar 1

tell menu bar item "View"

tell menu 1

click menu item "Clear Slices"

end tell

end tell

end tell

end tell

end tell

end Clear_Slices

1 reply

Inspiring
March 2, 2010

You will have to use Applescript's do javascript to run the javascript below.

    var desc = new ActionDescriptor();
        var ref = new ActionReference();
        ref.putEnumerated( stringIDToTypeID('slice'), charIDToTypeID('Ordn'), charIDToTypeID('Al  ') );
    desc.putReference( charIDToTypeID('null'), ref );
    executeAction( charIDToTypeID('Dlt '), desc, DialogModes.NO );

March 2, 2010

Hello Michael,

Thanks for your answer!

I have never used Applescript's do javascript to run javascript and I don't know how to do this.

I found a way to do this in an other discussion (How to run ps cs4 js script from applescript) :

set JavaScriptClearSlices to "myClearSlices();

function myClearSlices() {

var desc = new ActionDescriptor();

var ref = new ActionReference();

ref.putEnumerated( stringIDToTypeID('slice'), charIDToTypeID('Ordn'), charIDToTypeID('Al  ') );

desc.putReference( charIDToTypeID('null'), ref );

executeAction( charIDToTypeID('Dlt '), desc, DialogModes.NO );

}"


tell application "Adobe Photoshop CS4"

activate

set Doc_Ref to the current document

tell Doc_Ref

do javascript JavaScriptClearSlices ¬

show debugger on runtime error

display dialog the result

end tell

end tell

Is this the good method?

Inspiring
March 2, 2010

Michael's scriptlistener function requires no arguments you code looks fine to me. 'show debugger on runtime error' will launch and bring ExtendToolkit to the foremost app if an error occurs. It should also highlight where in the Javascript code the error took place.