Script to get all apps

Hi there, I’m writing a bash script to grab the full list of applications (this is for an app launcher). Only the GUI apps, I don’t want the command-line programs in bin directories.

Approach 1: use compgen,an obscure bash internal command, to get all executables (avoid lowercased filenames), then weed out the ones in a bin directory

tempfile=$(finddir B_COMMON_TEMP_DIRECTORY)/getapp_tmp.txt
tempfile2=$(finddir B_COMMON_TEMP_DIRECTORY)/getapp_tmp2.txt
settingsfile=$(finddir B_COMMON_TEMP_DIRECTORY)/getapps.txt
rm -f $tempfile; touch $tempfile
rm -f $tempfile2; touch $tempfile2
rm -f $settingsfile; touch $settingsfile

for i in 0 1 2 3 4 5 6 7 8 9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
	compgen -c $i >> $tempfile

for i in $(cat $tempfile)
	if echo $(which "$i") | grep -qv "/bin/"
		echo $i >>$tempfile2

sort $tempfile2 > $settingsfile

rm -f $tempfile; rm -f $tempfile2

This works, except that there are a few apps (QT and Java, mostly) that hide their executables in /boot/system/Applications/MyApp/bin and so on

Approach 2: Grab a listing off the Deskbar menu

tempfile=$(finddir B_COMMON_TEMP_DIRECTORY)/getapp_tmp.txt
settingsfile=$(finddir B_COMMON_TEMP_DIRECTORY)/getapps.txt
rm -f $tempfile; touch $tempfile
rm -f $settingsfile; touch $settingsfile

find  /boot/system//data/deskbar/menu/Applications/ -type l >$tempfile

sort $tempfile > $settingsfile

rm -f $tempfile

Much simpler, but there’s nothing to stop an app to put, for example, its helpfile in the Deskbar menu.

Any suggestions welcomed.


I’d do this by using the query system from the command line, by searching on attributes: the first one must be BEOS:TYPE==Be Application to filter out the binaries; the second string should look for the presence of the attribute SYS:NAME, that from what I see is present only in “real applications”, otherwise the result would also give libraries and CLI apps.

For some more info about the queries from the command line see here:
Scripting with the Be File System
Especially at middle of the page “Command-Line Queries and Index Manipulation”.


BEOS:TYPE=="application/x-vnd.Be-elfexecutable" :wink:

However: if from Terminal, I run this command:
query -fa "(name=="*")&&(SYS:NAME=="x-vnd*")"
query -fa "(name=="*")&&(SYS:NAME=="[xX][-][vV][nN][dD]*")&&(BEOS:TYPE=="application/x-vnd.Be-elfexecutable")"
I start to filter only “real applications” and I don’t see libraries and CLI apps: I am sure that could be improved!

This, which I quoted, will just give applications from /system

This one, instead
query -fa "(name=="*")&&(BEOS:APP_SIG=="application*")"
Will also give apps from /home, but however, will also give any binary file (eg printer addons). I will keep to figure out how to get only GUI applications.


Seems that

query -efa "(name=="*")&&(BEOS:APP_SIG=="application*")" | grep "/apps"

Will give, as results, only applications (from /system/apps and /config/apps) as result: also from subfolders.

Thanks, Giovanni!

I did try the query command and what tripped me up was that -a switch. Looks like files in packages are not regarded as on the same disk as far as this is concerned (cough - something for the --help documentation? - cough).

It still gives me some false positives: stuff in the trash, and in my projects folder, so I’ve tweaked it a little further:

tempfile=$(finddir B_COMMON_TEMP_DIRECTORY)/getapp_tmp
settingsfile=$(finddir B_COMMON_TEMP_DIRECTORY)/apps4liftoff.txt
patternfile=$(finddir B_COMMON_TEMP_DIRECTORY)/greppattern
rm -f $tempfile; rm -f $settingsfile; rm -f $patternfile

echo /boot/system/apps/ > $patternfile
echo /boot/home/config/apps >> $patternfile
echo /boot/home/config/non-packaged/apps/ >> $patternfile
echo /boot/system/non-packaged/apps/ >> $patternfile
echo /boot/system/preferences/ >> $patternfile
echo /boot/home/config/preferences/ >> $patternfile
echo /boot/home/config/non-packaged/preferences/ >> $patternfile
echo /boot/system/non-packaged/preferences/ >> $patternfile

query -efa "(name=="*")&&(BEOS:APP_SIG=="application*")" | grep -F -f $patternfile> $tempfile

sort $tempfile > $settingsfile

rm -f $tempfile
rm -f $patternfile

I’m still getting a few errors - old versions of that are incorrectly typed - but I can deal with that in my application.

Is this the greatest computing community or what?