do shell script find to list packages names not their contents

If this code finds package OMC 2.1.pkg it treats it like a folder.

set theFolder to choose folder
set theFiles to paragraphs of (do shell script "find -x " & quoted form of POSIX path of theFolder & " -type f ! -name '.*'  -print0 | /xargs -0 /basename -a |sort -d -f | uniq -d")
(* returns:
Archive.bom
Archive.pax.gz
Archive.sizes
background.tif
command.png
Description.plist
http--free.abracode.com-cmworkshop-on_my_command.html.webloc
Info.plist
package_version
PkgInfo
postflight
ReadMe.rtf
TXT.rtf"
instead of the name of the package*)

On a separate note is there a way to list the folders names only?

Identification of package directories is not something that can reliably be done (to the extent that it will match what Finder does) in the context of find.
See Apple’s documentation: Bundle Programming Guide > Packages and the Finder.

If you are satisfied with simply matching all directories that have a certain name, you could prefix your usual predicate arguments with something like -type d ( -name ‘.app’ -o -name '.pkg’ -o -name ‘*.bundle’ ) -prune -print0 -o (add name patterns as you like, adjust -print0 to -print as desired).

Hi Chrys,

Thanks for that and sorry for the late reply.

Yes I would like to exclude applications, packages and bundles. That would be great.
I have tried to follow your suggestions but unfortunately I cannot get the do shell script going, I only get errors.
I tried to include -type d ( -name ‘.app’ -o -name '.pkg’ -o -name ‘*.bundle’ ) -prune -print0 -o in it in a dozen different ways to no avail.

I would like to add the exclusions to the following line preserving xargs basename sort and uniq if possible. If there is a way I would like to exclude invisible files as well.

set theFiles to paragraphs of (do shell script "find -x " & quoted form of POSIX path of theFolder & " -type d -name '*.app' -o -name '*.pkg' -o -name '*.bundle'  -prune -print0 -o | /xargs -0 /basename -a |sort -d -f | uniq -d")

Thanks

Something like this is what I had in mind:

set theFolder to choose folder
set theFiles to paragraphs of (do shell script "find -x " & quoted form of POSIX path of theFolder & " -type d \\( -name '*.app' -o -name '*.pkg' -o -name '*.bundle' \\) -prune -print0 -o -type f ! -name '.*' -print0 | xargs -0 basename -a | sort -d -f | uniq -d")

Thanks Chris
much appreciated