Saturday, April 20, 2019

#1 2017-12-06 04:07:33 pm

rkubasiak
Member
Registered: 2010-08-03
Posts: 25

Read PLIST file, error when key name has a space

Can someone help this code snippet?

tell application "System Events"
    tell property list file "/Applications/App Store.app/Contents/Info.plist"
        tell contents
            set appVersion to value of property list item "InfoDictionary version"
        end tell
    end tell
end tell


If I change the item I'm trying to read to one with no space in its name, it will run fine.

Offline

 

#2 2017-12-06 05:03:29 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5623

Re: Read PLIST file, error when key name has a space

There is no "InfoDictionary version" key -- that's the English-like name sometimes given for CFBundleInfoDictionaryVersion:

Applescript:

tell application "System Events"
   tell property list file "/Applications/App Store.app/Contents/Info.plist"
       tell contents
           set appVersion to value of property list item "CFBundleInfoDictionaryVersion"
       end tell
   end tell
end tell

But that's not the application version, and will probably return "6.0" for every app. If you want the application version, just ask for it:

Applescript:

set appVersion to version of application "App Store"


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#3 2017-12-11 04:25:33 pm

rkubasiak
Member
Registered: 2010-08-03
Posts: 25

Re: Read PLIST file, error when key name has a space

Thanks Shane.  I felt like a dope not realizing I was looking at the pretty print names of keys.

Offline

 

#4 2019-02-09 10:30:56 am

GG
Member
Registered: 2019-01-14
Posts: 98

Re: Read PLIST file, error when key name has a space

Shane;
I read over the preceding posts and think that my situation is a slight bit different, because I need the changes to persist. I think your 'set appVersion to version of application "App Store"' reads the Launch Services database. That is likely only refreshed on startup and any changes would not likely be written back on shutdown (speculation; not knowing much about these services).

My app currently does not have a defined CFBundleTypeExtensions item in an apps Info.plist.

If I'm trying to read/write the value(s) for the CFBundleTypeExtensions item in an apps Info.plist in order to retrieve/save the extension on which my app is to act. This is so that, if a default metadata filetype is not defined, the user can define one for the app to use.

1) Is this wise to do.
2) What is the best way to go about achieving this goal (maybe it's not the via the plist?)

Offline

 

#5 2019-02-09 12:48:35 pm

GG
Member
Registered: 2019-01-14
Posts: 98

Re: Read PLIST file, error when key name has a space

Shane;

Just found a thread, in which you were involved, that basically stated that writing to the Info.plist file of an app is potentially dangerous. (https://macscripter.net/viewtopic.php?id=43193&p=1)

I suspected this, which is why I asked about the "correct" way to store a user default. If you have any advice or perhaps an URL for an example, I'd be very interested. In the meantime, I'll go over your book again and see if I missed something on this.

Offline

 

#6 2019-02-09 01:09:04 pm

GG
Member
Registered: 2019-01-14
Posts: 98

Re: Read PLIST file, error when key name has a space

I found the answer to what I wanted to do.

See: https://forum.latenightsw.com/t/storing … nces/864/6

It took me a while to find this post, but it looks like it should do what I am trying to do.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)