<NME> action-replicate-layers.cocoascript
<BEF> // @import 'actions/demo-inventory.cocoascript'

// generate code for layers
var runReplicateLayers = function() {
	StatisticsInventory.setStatus(Status.replicateID())
	FramerInventory.setUserSelection(currentSelection)

	var layers = []
	var pasteboardContent = []
	
	// var retinaProperty = userRetinaDefaults.myRetina || "retina"
//
// 	userRetinaDefaults.myRetina = retinaProperty
// 	saveDefaults(userRetinaDefaults)
	
	
	var currentPage = FramerInventory.getCurrentPage()
	var framerInventoryPage = FramerInventory.addPage(currentPage)
	FramerInventory.cleanPage(framerInventoryPage)
	
	
	if (selection != nil) {
		for (var i = 0; i < [selection count]; i++) {
			var currentLayer = [selection objectAtIndex: i]
			var layer = new Layer([currentLayer name])
			layer.addState(currentLayer)
			layers.push(layer)
		[currentDocument showMessage:ViewInventory.smileWarning() + "Select layers"]
		return
	}

	if (!DemoInventory.isRegistered() && DemoInventory.actionsLeft() <= 0) {
		showExpiredModal()
		return
	}

	for (var i = 0; i < [sortedSelection count]; i++) {
		var currentLayer = [sortedSelection objectAtIndex: i]
		var layer = new Layer([currentLayer name])
		layer.composeState(currentLayer)
		layers.push(layer)
	}


	for (var i = 0; i < layers.length; i++) {
		pasteboardContent += layers[i].printLayer()
	}

	[[NSPasteboard generalPasteboard] setString:pasteboardContent  forType:NSStringPboardType];
	DemoInventory.actionUsed()
	FramerInventory.showDoneMessage()

	StatisticsInventory.setStatus(Status.waitingID())
	return pasteboardContent
}

<MSG> Hierarchical selection

- added selection sorting into actions
- changed “corderRadius” to “borderRadius” for new Framer syntax

<DFF> @@ -8,20 +8,16 @@ var runReplicateLayers = function(context) {
 	var layers = []
 	var pasteboardContent = []
 	
-	// var retinaProperty = userRetinaDefaults.myRetina || "retina"
-//
-// 	userRetinaDefaults.myRetina = retinaProperty
-// 	saveDefaults(userRetinaDefaults)
-	
-	
 	var currentPage = FramerInventory.getCurrentPage()
 	var framerInventoryPage = FramerInventory.addPage(currentPage)
 	FramerInventory.cleanPage(framerInventoryPage)
 	
 	
 	if (selection != nil) {
-		for (var i = 0; i < [selection count]; i++) {
-			var currentLayer = [selection objectAtIndex: i]
+		var sortedSelection = FramerInventory.organiseSelection(selection)
+		
+		for (var i = 0; i < [sortedSelection count]; i++) {
+			var currentLayer = [sortedSelection objectAtIndex: i]
 			var layer = new Layer([currentLayer name])
 			layer.addState(currentLayer)
 			layers.push(layer)

Hierarchical selection