Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Applescript: read plist doesn't work

Hello,


In every application, there is a info.plist (in contents).

I want to read, from that plist, the value of the item "Icon File" (it's a string).

I tried this:


--selecting app


repeat

set appfile1 to (choose file with prompt "Choose an app to download the icon:")

set extention to get file type of (info for (appfile1))

if extention is "APPL" then

exit repeat

else

display dialog "Please select an app, not another file" with title "Error" buttons {"Ok"} default button "Ok"

end if

end repeat


--select plist


set appfile11 to do shell script "echo " & appfile1 & "Contents:info.plist"


--tell system events

tell application "System Events"

set p_list to property list file (appfile11)

value of property list item "Icon File" of p_list

end tell



(I tried with "of property list item "Information Property List"" and without it, because that item doesn't show up if I read the plist in 'Xcode', but it does in 'Plist Edit Pro')


Error:


error "System Events kreeg een fout: property list item \"Icon File\" of property list file \"Macintosh HD:Users:Isaiah:Downloads:UnRarX.app:Contents:Info.plist\" kan niet worden opgevraagd. " number -1728 from property list item "Icon File" of property list file "Macintosh HD:Users:Isaiah:Downloads:UnRarX.app:Contents:Info.plist"


Please help me,


Isaiah v. Hunen

Applescript-OTHER, Mac OS X (10.7.2)

Posted on Jun 6, 2012 11:04 AM

Reply
Question marked as Best reply

Posted on Jun 6, 2012 11:58 AM

Hi,


The error is that the name of the property list item is not good.


To get the real name in "Property List Editor" : menu "View" --> "Show Raw key/value"


set appfile11 to ((appfile1 as string) & "Contents:Info.plist")

tell application "System Events"

valueofproperty list item "CFBundleIconFile" ofcontentsofproperty list fileappfile11

endtell

3 replies
Question marked as Best reply

Jun 6, 2012 11:58 AM in response to Drake69

Hi,


The error is that the name of the property list item is not good.


To get the real name in "Property List Editor" : menu "View" --> "Show Raw key/value"


set appfile11 to ((appfile1 as string) & "Contents:Info.plist")

tell application "System Events"

valueofproperty list item "CFBundleIconFile" ofcontentsofproperty list fileappfile11

endtell

Jun 6, 2012 12:02 PM in response to Drake69

You are not using the correct key - the actual key name is CFBundleIconFile (in Xcode, you can see the raw keys by making that selection from the Editor menu).


Also note that you can filter what is selectable in the choose file dialog by using the content type (the old file types are not really used anymore):


setappfile1to (choose filewith prompt"Choose an app to download the icon:"of type"com.apple.application-bundle")

Applescript: read plist doesn't work

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.