How Do I Get List of Recent Apps?

How do I get the list of recent apps, as tracked by KM, as shown in this screenshot of picking an app for a KM Action:

I need to build this list and use in a KM Prompt for User Input to allow the user to select one of these apps.


1 Like

That is not exposed in any way except via the Keyboard Maestro Recent Applications.plist file which is only updated when the Engine quits.

Thanks, Peter.

OK, anyone know the best way to get the list of key values from a plist?

I have this shell script I found and modified. It works, but it is kinda hokey because I had to use {print $3 " " $4} to get both words of the Name key.

How do I get ALL words in the Name key?

/usr/libexec/PlistBuddy -c "Print" "/Users/YourUserName/Library/Application Support/Keyboard Maestro/Keyboard Maestro Recent Applications.plist" | awk '/Name = /{print $3 " " $4}'

Here’s a section of the plist file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">
		<string>Script Debugger</string>

Hey JM,

Well shoot. I’m ticked I can’t figure out how to get PlistBuddy to print values from these nested <dict> items in the plist tree.

Nevertheless the easiest way to get these values via AppleScript is probably to use System Events:

set plistFilePath to "~/Library/Application Support/Keyboard Maestro/Keyboard Maestro Recent Applications.plist"

tell application "System Events"
  tell property list file plistFilePath
    tell property list items
      set recentAppList to value of property list item "Name"
    end tell
  end tell
end tell

Not that there’s anything wrong with parsing the plist.

I’d change the awk around just a little to make things a little more direct though:

awk 'BEGIN { FS = " = " }; /Name =/ { print $2 }'

FS == Field-Separator.


Chris, this is perfect. :+1:

I had done an exhaustive search of the Internet, and found many half-baked scripts, but none that would do the job.

Your simple script is just right!

Many thanks.