Skip to content

Instantly share code, notes, and snippets.

@me7
Last active March 31, 2017 09:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save me7/84ce33d84908c8d723c201492d029986 to your computer and use it in GitHub Desktop.
Save me7/84ce33d84908c8d723c201492d029986 to your computer and use it in GitHub Desktop.
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