show recent apps icon in the blog sample three by three buttons floating menu

Hi, I am working to do this based upon the existing 3*3 buttons floating menu.

I plan to dynamically set each button as one of the latest app, so kind of like command+tab usage but now showing at the mouse point.

I am now looking for way to update the menu button with an image and text of the lastest app, but it seems i can only change the text but not the image, I have the below script for button "B" for example that will run on first load. Let me know what did i do wrongly

on nameScript(itemUUID)

tell application "System Events"

set appList to (name of every process whose background only is false) as list

end tell

if (count of appList) > 1 then

set secondLastApp to item 2 of appList

else

set secondLastApp to "No app found"

end if

if secondLastApp is not "No app found" then

set appPath to POSIX path of (path to application secondLastApp)

set iconPath to ""

if (do shell script "test -e " & quoted form of (appPath & "Contents/Resources/icon.icns") & " && echo found") is "found" then

set iconPath to appPath & "Contents/Resources/icon.icns"

else if (do shell script "test -e " & quoted form of (appPath & "Contents/Resources/AppIcon.icns") & " && echo found") is "found" then

set iconPath to appPath & "Contents/Resources/AppIcon.icns"

end if

else

set iconPath to ""

end if

return "{"BTTMenuItemText":"" & secondLastApp & "", "BTTMenuItemIconPath":"" & iconPath & ""}"

end nameScript

Try using these properties to set a path:

BTTMenuItemIconType = 3
BTTMenuItemIconPresetPath

What might be easier:

Starting with 4.746 you can dynamically load items into a floating menu using java script. This is not yet documented but the same scripts as for "Show Context Menu (New)" and "Choose From List" will work.

(additional supports property templateItemUUID to use an existing floating menu item as template)

In v 4.738 alpha you can use this java script to create a menu with the recently used applications:

async function retrieveJSON() {
		let apps = await BTTActions.copyLaunchedApplicationsInFrontToBackOrder();
		let menuItems = [];
		
		 for (let app of apps) {
    let item = {
      title: app.CFBundleName,
      action: `js::(async () => {runShellScript({script: 'open "${app.BundlePath}"'})})()`, 
      icon: `path::${app.AppIconPath}::width@@40`
    };
    menuItems.push(item);
  } 
  
 
  return JSON.stringify(menuItems);
}

I can not run your latest javascript in float menu level as your screenshot and code sample suggests. I upgrade my version to 4.739. When I verify the script, there is a popup alert saying
a identifier can't go after this identifier, and it highlights the "async function" string at the start of the script.

you need to enter it at the menu level, not at the menu item level.

Could you post s screenshot
of the script input?

it is in the menu level. I guess it might be BTT does not know this is a javascript but still think this is apple script. In menu level, there is no script type selection, not like item level.

@yihui_lu could you check whether v4.741 solves this? (uploading now)

Not working for me

Updated to the latest version, restarted

Screenshot 2024-10-07 at 13.22.13

Clicking "run script" doesn't give any output on "Script Result"

you also need to enter the name of the function that shall be called (in this case retrieveJSON) in the async function to call field

And we have liftoff! :smiley:

I don't know why calendar doen's have an icon though...

I am using your latest 4.746. It is unstable in my mac. I am still using the import preset from

then I delete the buttons inside and add the retrieveJSON to my menu level. after the menu pops up by my trigger, it actually contains latest app icons that i can see. But then BTT crash and reopen. There is something wrong with this version. Please have a look and let me know.

I am also curious why the menu level script execution is based on a interval as your setting that it execute per 6 seconds. Is it more reasonable that the menu should execute the script to pop buttons when and only when it appear?

A few crashfixes and improvements are now available in v 4.747 alpha!

Here is a nice little example that uses the new radial menu style and shows the last 10 apps. It shows when doing a three finger swipe down, and selects the item once all fingers have been removed from the trackpad

Preset:
RadialAppSwitcher.bttpreset (27.5 KB)

2 Likes

This preset works great...

I'm curious if we can show not just currently open applications (like ⌘+↹)... but also ones that were recently closed... could be up to 5 for example...

BTT would need to keep track of the closed applications, can be done but is currently not implemented.

Maybe you could adapt it to show some of your most used apps instead?

1 Like

Hi Andreas, the new circle shape menu is really neat and I like it very much.
In the end I decide to go back to the square 3X3 menu since my purpose is to have a better command+tab so I want the 2nd position icon is always in the middle of the 3X3 menu. In that case, if i pop the menu out and directly click i will switch to the previous app, i can keep on doing this to swap between the latest two apps without looking for the app icon. I give my current script, it basically has an additional logic to manipulate icon index so app icons are shown clockwise from new to old and keep previous one in the middle(index 1 to index 4). I will like to know how can i change the icon's circle boundary to a square with round corner? I am using your current template to only show icon image but I will like the boundary to be square to fit better into this 3X3 menu.


The changed script is as below:
async function retrieveJSON() {
let apps = await BTTActions.copyLaunchedApplicationsInFrontToBackOrder();
let menuItems = ;
let i=0;
for (let app of apps) {
if(i>=9) {break;}
i++;
let item = {
templateItemUUID: "BFBD1B46-0E72-49CF-B4DB-C2CB017E82B2",
title: "",
action: js::(async () => {runShellScript({script: 'open "${app.BundlePath}"'})})(),
icon: path::${app.AppIconPath}::width@@30
};
menuItems.push(item);
}
let newIndexSequence = [0, 2, 3, 8, 1, 4, 7, 6, 5];
let newMenuItems = newIndexSequence.map(i => menuItems[i]);

return JSON.stringify(newMenuItems);
}

Oh, I found how to change it. since the template is from the imported radial app switcher, I directly modify that one and get the effect I want.
image

1 Like

I'm sorry, I'm new, I downloaded the preset but how do I use it?
Where do I go to set some sort of a trigger for it? Do I need the javascript I posted?