-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathLock or Unlock.jstalk
40 lines (31 loc) · 1.95 KB
/
Lock or Unlock.jstalk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Lock or Unlock (option cmd l)
// v.01b
// This command allows you to lock or unlock all objects within a selection. If the selection includes some locked layers already, the command will unlock them. Otherwise, it will lock all layers within the selection.
// The Opt-Cmd-L (⌥⇧L) shortcut may be used to run the command multiple times.
// Sketch's existing Lock/Unlock Layers command (⌘⇧L) does not effectively handle selections that include both locked and unlocked objects. Instead of uniformly locking or unlocking all objects within the selection, it toggles the state of each layer independently, maintaining the mixed setting. This command is designed as a substitute.
// If you'd prefer to favor locking objects over unlocking them, you may set this preference in the User Variables section.
// Copyright (c) 2014 Doug Downing. All rights reserved.
// Email: drawingkit@dougdowning.com // Website: www.dougdowning.com
// USER VARIABLES
var lock = false; // Set to true to lock all objects by default
// SCRIPT STARTS HERE
// Check for locked objects
var lockedObjects = new Array();
for (var i=0; i<selection.count(); i++) {
if (selection[i].isLocked() == true) {
lockedObjects.push(selection[i]);
}
}
// Lock or unlock
for (var i=0; i<selection.count(); i++) {
if ((lock == true && lockedObjects.length < selection.count()) || lockedObjects.length == 0) {
selection[i].setIsLocked(true);
}
else {
selection[i].setIsLocked(false);
}
}
// NOTES
// This script is not to be distributed, shared, modified, etc. without written permission of the author. (See copyright notice above.)
// The script is provided “as is", to be used at your own risk, with no warranties of any kind, whether expressed or implied. Under no circumstances shall the author be liable for direct, indirect, special, incidental, or consequential damages resulting from the use, misuse, or inability to use this script.
// ---------------------------------------------------------------