Posted on 02-21-2012 09:38 PM
With the impending upgrade to Lion in our environment, I'm hoping to save some time and seek out all of the 'PowerPC' applications that are using Rosetta so I can give all of the departments the good news on what software they get to abandon or re-buy. I know we've got a lot in use on student computers, but short of running system profiler on a bunch of them and just looking, does anybody know a quick way to pull this information? It doesn't seem to be pulled in the Casper application inventory reports from what I can find, and I'm thinking that for an Extension attribute, you'd have to do a separate one for each app. Anybody have any thoughts?
Posted on 02-21-2012 09:43 PM
You can use this as an AppleScript.
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
Posted on 02-21-2012 09:56 PM
I did not write this applescript. I found it somewhere so if anyone knows where it came from please provide the source. What it does is searches your computer and creates a new folder on your desktop that contains shortcuts to all of your PPC apps and then gives you the choice to delete them if you wish. If you don't want to delete them then you have a folder with all of your PPC apps listed.
Posted on 02-21-2012 10:21 PM
I might be able to do something with that. I'm hoping for more of a reporting engine though than something to take action on files. I just want to know the info, not do anything to the computer...
Posted on 02-22-2012 09:19 AM
The system_profiler command should give you what you need:
system_profiler SPApplicationsDataType
It will return "Kind" for each application:
- Kind: PowerPC
- Kind: Universal
- Kind: Intel
Add a little grep to the mix and you can get a list of PowerPC only applications and their paths:
system_profiler SPApplicationsDataType | grep -A 3 PowerPC | grep Location
This could probably be cleaner but it gets the job done.
Posted on 02-23-2012 11:27 AM
@talkingmoose My test is usually readability first and efficiency second (EDIT: just tested and you win there too).
The big problem typically with people that use multiple |, greps, awks, and seds is that they are just not using all the features and it ends up being incredibly incomprehensible.
I actually had to ask around for how to accomplish this in awk because I came close but couldn't pull it off on my own.
This is actually a lot harder to read but accomplishes the task at hand.
system_profiler SPApplicationsDataType | awk '/^[[:space:]]*$/{n=0}/PowerPC/{n++}/Location/&&n'
The only problem I could see with yours is if the Location line was more lines away...I don't have anything with PowerPC apps to test but Universal -> Location on my iMac varies from 3-6 lines away :(.
tl;dr I like yours better :)
Posted on 02-23-2012 01:41 PM
Hi Ryan!
I'll make no excuses regarding my coding other than it was down and dirty. Your string and mine returned the same results on my machines but that's not to say they normally would.
Thanks for finding a cleaner way of doing it. :-D
Posted on 02-23-2012 03:19 PM
Same results from both here as well - thanks for the chance to learn some more awk-fu.
Posted on 02-27-2012 12:17 PM
I found the following script:
#!/bin/sh # Author: Robert Harder, http://blog.iharder.net # Variable and temp file setup OUTPUT=~/Desktop/ppc-only-quick-and-dirty.txt H=$(tput setab 4; tput setaf 3; tput bold) R=$(tput sgr0) # Execute search echo "This will just take a moment..." /bin/echo -n "Looking for ${H} PowerPC ${R} applications..." system_profiler SPApplicationsDataType 2> /dev/null | awk 'BEGIN { RS="" } /PowerPC/ {print PrevLine} {PrevLine=$0}' > "$OUTPUT" open -a "TextEdit" "$OUTPUT"
It's not what John was looking for, since his goal is to have Casper pull that information from the client, but the script above will give you a quick overview in a txt file.
Posted on 02-28-2012 04:29 PM
Word of warning, this will give false positives
system_profiler SPApplicationsDataType | awk '/^[[:space:]]*$/{n=0}/PowerPC/{n++}/Location/&&n'
Any application with PowerPC in it's title will show up as Kind PowerPC even though it may not be. I have one on my machine!!!
PowerPC Help:
Version: 4.7.3 Last Modified: 04/08/2011 22:56 Kind: Intel 64-Bit (Intel): No Location: /Library/Application Support/Shark/Helpers/PowerPC Help.app
Change "PowerPC" to "^ {6}Kind: PowerPC" will reduce the risk of false positives and you could also tidy up the output
system_profiler SPApplicationsDataType | awk -F ":" '/^[[:space:]]*$/{n=0}/^ {6}Kind: PowerPC/{n++}/Location/&&n{$1="";sub(/^[ ]+/, ""); print}'
^/ {6} means starts with 6 spaces
-F is a field separator, in this case use : as a separator
$1 is made to equal nothing (hence everything before the field separator is blanked and so only everything after the field separator is printed).
sub is a substitution, so remove all leading whitespace in this example.
Posted on 02-28-2012 07:50 PM
Of course!
I didn't think of PowerPC being in an app title. :(
Nice catch.