Skip to content

Instantly share code, notes, and snippets.

@nikolay-n
Last active October 1, 2020 15:43
Show Gist options
  • Save nikolay-n/a68e9d91f5a5e353214687fc07c82037 to your computer and use it in GitHub Desktop.
Save nikolay-n/a68e9d91f5a5e353214687fc07c82037 to your computer and use it in GitHub Desktop.
One-liner to extract team ids of installed apps.
#!/usr/bin/env bash
mdfind kMDItemContentType="com.apple.application-bundle" | perl -ne 's/ /\\ /g, `codesign -d -vvvv $_`' 2>&1 | egrep "Authority=(3rd|Soft|Dev|Mac|Apple Dev)" | sort | uniq | perl -ne '/[^=]+=[^:]+: (.+)\s\((.+)\)$/ && print "$2=$1\n"'
#!/usr/bin/env bash
perl -e 'open(my$fb, "-|", "mdfind kMDItemContentType=\"com.apple.application-bundle\"") or exit(1);my%cache;while(<$fb>){ chomp;s/\\?([ \(\)\$])/\\$1/g;open(my$fh,"-|","codesign -dvvvv $_ 2>\&1") or exit(1);my%attrs=();while(my$line=<$fh>){chomp($line);my($attr,$value)=split(/=/,$line, 2);if(exists $attrs{$attr}){ if(ref($attrs{$attr}) eq "ARRAY"){ push @{$attrs{$attr}},$value;}else{ my$prev=$attrs{$attr};$attrs{$attr}=[$prev,$value];}}else{ $attrs{$attr}=$value;}}my$auth=$attrs{Authority};my($team_id,$company,$rev_domain);my$bundle_id=$attrs{Identifier};if($bundle_id){ if($bundle_id=~/^(\w+\.\w+)/){ $rev_domain=$1;}}if(ref $auth eq "ARRAY"){ my$dev=@$auth[0];if($dev=~/[^:]+:\s(.+)\s\((.+)\)$/){ $company=$1;$team_id=$2;}}if(!$team_id){ $team_id=$attrs{TeamIdentifier};$company=$rev_domain;if($company=~/^(com|org)\./){ $company=ucfirst((split(/\./,$company, 2))[1]);}}print "$team_id=$company\n" if $team_id and ($team_id ne "not set") and !exists $cache{$team_id};$cache{$team_id}++;}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment