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
#!/boot/system/bin/bash
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
do
compgen -c $i >> $tempfile
done
for i in $(cat $tempfile)
do
if echo $(which "$i") | grep -qv "/bin/"
then
echo $i >>$tempfile2
fi
done
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
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”.
However: if from Terminal, I run this command: query -fa "(name=="*")&&(SYS:NAME=="x-vnd*")"
OR: 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.
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: