By looking through System Information I discovered that I have several hundred old PowerPC apps that won't run under Lion without Rosetta any more. I'm OK with that, but, short of manually deleting old PowerPC apps one-by-one, is there a way to purge my Mac Pro of all PowerPC apps and related code in a batch fashion?
As I mentioned in you can locate the PowerPC applications on your Mac by opening System Profiler (Snow Leopard and earlier)/System Information (Lion), choosing Applications, and then sorting by Kind. The problem is that you can't then delete applications from within System Profiler. Additionally, there's no way to create a Smart Folder or Spotlight search that searches based on PowerPC code.
But, there is a way. And that way is AppleScript. Copy the following script and paste it into AppleScript Editor (found in /Applications/Utilities):
set the searchResult to do shell script "system_profiler SPApplicationsDataType"
set thesePaths to {}
repeat with i from 1 to the count of paragraphs of the searchResult
if paragraph i of the searchResult contains "PowerPC" then
repeat with x from 1 to 5
if (paragraph (i + x) of the searchResult) contains "Location:" then
set the end of thesePaths to (text 17 thru -1 of (paragraph (i + x) of the searchResult))
end if
end repeat
end if
end repeat
if thesePaths is not {} then
set theseApplicationFiles to {}
repeat with i from 1 to the count of thesePaths
set the end of theseApplicationFiles to (item i of thesePaths) as POSIX file as alias
end repeat
else
return "NO MATCHES"
end if
tell application "Finder"
set the folderOfAliases to make new folder at desktop
repeat with i from 1 to the count of theseApplicationFiles
make alias file to (item i of theseApplicationFiles) at folderOfAliases
end repeat
activate
open folderOfAliases
display dialog "Do you want to delete the original PowerPC apps?" buttons {"Cancel", "Delete All"} default button 1
delete theseApplicationFiles
delete folderOfAliases
end tell
Given that you'll likely need to run this just once, you can run it directly from within AppleScript Editor. Or, you can save it as an Application, plunk it on your Desktop, and then run it by double-clicking on it.
What happens is that the AppleScript looks through System Information/System Profiler for PowerPC applications. It then creates a folder that contains aliases of all the applications its finds and puts it on the Desktop. You are then asked if you'd like to delete the original PowerPC apps. Click Delete All and the original files pointed to by the aliases as well as the folder full of aliases are moved to the Trash. If you click Cancel instead, the aliases remain and the original applications stay put.
Choosing Cancel is a good idea if you want to take a close look at what you will be deleting when you click on Delete All. (Of course you could always recover the files from the Trash provided you don't empty it.) And, of course, it's never a bad idea to back up your data before doing something like this.
If this script fails because of permission issues, you have this second option below. Note that in this case, once you click Delete All, your PowerPC applications will be deleted permanently--there's no going back. So be sure you really want to see the last of them.
set the searchResult to do shell script "system_profiler SPApplicationsDataType"
set thesePaths to {}
repeat with i from 1 to the count of paragraphs of the searchResult
if paragraph i of the searchResult contains "PowerPC" then
repeat with x from 1 to 5
if (paragraph (i + x) of the searchResult) contains "Location:" then
set the end of thesePaths to (text 17 thru -1 of (paragraph (i + x) of the searchResult))
end if
end repeat
end if
end repeat
if thesePaths is not {} then
set theseApplicationFiles to {}
repeat with i from 1 to the count of thesePaths
set the end of theseApplicationFiles to (item i of thesePaths) as POSIX file as alias
end repeat
else
return "NO MATCHES"
end if
tell application "Finder"
set the folderOfAliases to make new folder at desktop
repeat with i from 1 to the count of theseApplicationFiles
make alias file to (item i of theseApplicationFiles) at folderOfAliases
end repeat
activate
open folderOfAliases
display dialog "Do you want to delete the original PowerPC apps?" & linefeed & linefeed & "THIS CANNOT BE UNDONE." buttons {"Cancel", "Delete All"} default button 1 with icon 2
--delete theseApplicationFiles
repeat with i from 1 to the count of theseApplicationFiles
do shell script "rm -R " & quoted form of the POSIX path of (item i of theseApplicationFiles) with administrator privileges
end repeat
delete folderOfAliases
end tell