Umenu autopopulate - always alphabetical order?


    Jun 27 2011 | 1:35 pm
    Is there any way to autopopulate in order of date created?

    • Jun 27 2011 | 11:13 pm
      If you put this JavaScript code into a [js] and send it the message "read path/to/the/folder" it will output all files by date modified/created ascending.
      function read(path) {
      	var folder = new Folder(path);
      	var allFiles = new Array();
      	var i = 0;
      	 while (!folder.end) {
      	 var d = new Date(
      			folder.moddate[0],
      			folder.moddate[1],
      			folder.moddate[2],
      			folder.moddate[3],
      			folder.moddate[4],
      			folder.moddate[5],
      			0);
                      // sort out hidden files and folders
                      // and write others into an array
      		if (folder.filename && folder.filetype!="fold") {
      			allFiles[i] = {name: folder.filename, date : Number(d)};
      			i++;
      
      		}
      		folder.next();
      	 }
               folder.close();
               // sort the array by date asc
      	 allFiles.sort(
      		function(a, b){
      			return a.date-b.date;
      		}
      	);
              // and finally send the file names to outlet
      	for(var j=0;j
      If you want to change the order to descending change the line: "return a.date-b.date;"
      into: "return b.date-a.date;"
      jan
    • Jun 28 2011 | 7:43 am
      Wow - thank you so much for sharing this.
      Awesome!
    • Jun 28 2011 | 8:10 am
      ;) !
    • Nov 22 2015 | 12:28 am
      Hi, It's an old thread, but I'm interested in this js. When I send "read path..." I get: "no read function" ?? did something change in js since 2011 ?
      Thanks,
      Yoann
    • Nov 22 2015 | 1:18 am
      For some reasons the last lines are missing - also it was written on Windows, just realized that hidden files on Mac were not filtered out. this should work:
      function read(path) {
      	var folder = new Folder(path);
      	var allFiles = [];
      	while (!folder.end) {
      		var d = new Date(
      			folder.moddate[0],
      			folder.moddate[1],
      			folder.moddate[2],
      			folder.moddate[3],
      			folder.moddate[4],
      			folder.moddate[5],
      			0
      		);
              // sort out hidden files and folders
              // and write others into an array
      		if (
      			folder.filename
      			&& folder.filetype !="fold"
      			&& folder.filename.indexOf(".") != 0
      		) {
      			allFiles.push({ "name": folder.filename, date : d.getTime()});
      		}
      	
      		folder.next();
      	 }
           folder.close();
           // sort the array by date asc
      	allFiles.sort(
      		function(a, b){
      			return a.date-b.date;
      		}
      	);
          // and finally send the file names to outlet
      	for(j in allFiles) {
      		outlet(0, allFiles[j]["name"]);
      	}
      }
      
      
    • Nov 22 2015 | 3:57 pm
      it's working.
      Thanks !!
    • Nov 22 2015 | 4:52 pm
      .. just saw that the old post used back-ticks for code formatting and they were parsed wrongly. changed them to pre-tags...