Skip to main content
prema56615405
Inspiring
May 29, 2017
Answered

Unlocking sublayers - Applescript

  • May 29, 2017
  • 6 replies
  • 3532 views

Hi ACP's,

This is Prem. Good day to you.

I am trying to unlock all the layers by using the below script

"set the properties of every layer to {locked:false}"

But the problem is sublayers are not unlocked.

Please help

Thanks,

Prem

This topic has been closed for replies.
Correct answer prema56615405

Got the correct answer in applescript. Thanks to Silly-V and Loic.Aigon.

I have combined your both the scripts and putting below:

on unlockLayer(subjectLayer)

  local thisSubLayer

  tell application "Adobe Illustrator"

  set the properties of subjectLayer to {locked:false}

  if (count of layers in subjectLayer) > 0 then

  repeat with i from 1 to count of layers in subjectLayer

  set thisSubLayer to layer i in subjectLayer

  -- set the properties of thisSubLayer to {locked:false}

  my unlockLayer(thisSubLayer)

  end repeat

  end if

  end tell

end unlockLayer

tell application "Adobe Illustrator"

  local thisLayer, activeDoc

  if (count of documents) > 0 then

  set activeDoc to front document

  repeat with i from 1 to count of layers of activeDoc

  -- set the properties of layer i of front document to {locked:false}

  set thisLayer to layer i of front document

  -- set the properties of thisLayer to {locked:false}

  my unlockLayer(thisLayer)

  end repeat

  end if

end tell

6 replies

Loic.Aigon
Legend
June 7, 2017

Hi

Great ! I understand now why my recursive call didn't work. It needed the "my" command obviously. Applescriot has its own logic

Apart from that, I got an execution error at first:

But then I commented out "as layer" like this

set thisLayer to layer i of front document --as layer

And it ended working.

Good work

prema56615405
prema56615405AuthorCorrect answer
Inspiring
June 7, 2017

Got the correct answer in applescript. Thanks to Silly-V and Loic.Aigon.

I have combined your both the scripts and putting below:

on unlockLayer(subjectLayer)

  local thisSubLayer

  tell application "Adobe Illustrator"

  set the properties of subjectLayer to {locked:false}

  if (count of layers in subjectLayer) > 0 then

  repeat with i from 1 to count of layers in subjectLayer

  set thisSubLayer to layer i in subjectLayer

  -- set the properties of thisSubLayer to {locked:false}

  my unlockLayer(thisSubLayer)

  end repeat

  end if

  end tell

end unlockLayer

tell application "Adobe Illustrator"

  local thisLayer, activeDoc

  if (count of documents) > 0 then

  set activeDoc to front document

  repeat with i from 1 to count of layers of activeDoc

  -- set the properties of layer i of front document to {locked:false}

  set thisLayer to layer i of front document

  -- set the properties of thisLayer to {locked:false}

  my unlockLayer(thisLayer)

  end repeat

  end if

end tell

pixxxelschubser
Community Expert
Community Expert
June 7, 2017

All seems to be ok.

But only for interest: did someone try the code in my post #12 ? (I know, this is not pure AppleScript )

Loic.Aigon
Legend
June 3, 2017

yes that's what i offered in my second reply. But pur friend seems obssesed with applescript

Silly-V
Legend
June 3, 2017

Hey Guys! Awesome, I was able to help get this figured out with a clue from this AppleScript expert I met! Turns out, that tell block also needs to be inside the function too.

Then, I was having a personal error because I was trying to get "layer i of layers of thisLayer", while the syntax it likes is instead "layer i of thisLayer".

Have fun yall!

on unlockLayer(subjectLayer)

  local thisSubLayer

  tell application "Adobe Illustrator"

  set the properties of subjectLayer to {locked:false}

  if (count of layers in subjectLayer) > 0 then

  repeat with i from 1 to count of layers in subjectLayer

  set thisSubLayer to layer i in subjectLayer

  -- set the properties of thisSubLayer to {locked:false}

  my unlockLayer(thisSubLayer)

  end repeat

  end if

  end tell

end unlockLayer

tell application "Adobe Illustrator"

  local thisLayer, activeDoc

  if (count of documents) > 0 then

  set activeDoc to front document

  repeat with i from 1 to count of layers of activeDoc

  -- set the properties of layer i of front document to {locked:false}

  set thisLayer to layer i of front document as layer

  -- set the properties of thisLayer to {locked:false}

  my unlockLayer(thisLayer)

  end repeat

  end if

end tell

Loic.Aigon
Legend
June 2, 2017

I tried recursivity with no luck. The editor won't allow the call inside some function scope.

curious about this

pixxxelschubser
Community Expert
Community Expert
June 3, 2017

Hi Loic.Aigon​,

why not using your own suggestion? This should do the job exactly.

I don't know the AppleScript syntax, but it should be something like that pseudocode

set js to "var doc = app.activeDocument; unlockLayers ( doc.layers ); var unlockLayers = function ( layers ) {var n = layers.length, layer; while ( n-- ) { layer = layers; layer.locked = false; layer.layers.length && unlockLayers ( layer.layers ); }};"

tell application "Adobe Illustrator"

    do javascript js

end tell

Have fun

Loic.Aigon
Legend
June 2, 2017

Probably possible but gave it a try with no success and to be honest too time consuming. I can't think of a reason where I could prefer using Applescript over Javascript unless of course I need to drive external apps or system commands. But even them, I would use do javascript for Illustrator.

Feel free to explain me why you are such in need for an applescript

FWIW

Loic

Silly-V
Legend
June 2, 2017

One of the Creative Developer Summit attendees is an AppleScript expert! I had asked him for help, but have not yet had the chance to send him my sample code to figure out why it's not working.

Loic.Aigon
Legend
June 2, 2017

That would not work with deeper nested layers

prema56615405
Inspiring
June 2, 2017

Yes. You are correct.

Do you have any solution in applescript for this?

Loic.Aigon
Legend
May 29, 2017

Here is a JS approach :

var doc = app.activeDocument;

var unlockLayers = function ( layers ) {

  var n = layers.length, layer;

  while ( n-- ) {

  layer = layers;

  layer.locked = false;

  layer.layers.length && unlockLayers ( layer.layers );

  }

}

unlockLayers ( doc.layers );

HTH

Loic

prema56615405
Inspiring
May 29, 2017

Actually i need the apple script.

Loic.Aigon
Legend
May 29, 2017

tell application "Finder"

  set f to choose file

  set {nExt} to ({name extension} of f)

end tell

if nExt = "jsx" then

  tell application "Adobe Illustrator"

  if (count of documents) > 0 then

  do javascript f

  end if

  end tell

end if