Skip to content

Instantly share code, notes, and snippets.

@me7
Last active Mar 31, 2017
Embed
What would you like to do?
lightning launcher select first item in folder
var item = LL.getEvent().getItem();
if ( item.getType() != 'Folder' )
{
alert('Not a folder');
return;
}
var items = item.getContainer().getItems();
var count = items.getLength();
if ( count == 0 )
{
alert('Empty folder');
return;
}
var minItem;
var i = 0;
/* make sure we find at least a shortcut */
while ( i < count )
{
minItem = items.getAt(i++);
if ( minItem.getType() == 'Shortcut' )
{
break;
}
}
if ( i == count )
{
alert('No shortcut found');
return;
}
var minTop = minItem.getCell().getTop();
var minLeft = minItem.getCell().getLeft();
/* find the topmost leftmost shortcut */
for ( ; i < count; i+=1 )
{
item = items.getAt(i);
if ( minItem.getType() != 'Shortcut' )
continue;
var r = item.getCell();
/* check if it is the topmost leftmost */
if ( (r.getTop() < minTop) && (r.getLeft() < minLeft) )
{
minTop = r.getTop();
minLeft = r.getLeft();
minItem = item;
return;
}
}
/* launch app */
minItem.launch();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment