Problem reading .plist file inside app package

Deploying to Mac OS? Ask Mac OS specific questions here.

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

coyoteconscious
Posts: 9
Joined: Sun Nov 03, 2019 6:30 pm

Problem reading .plist file inside app package

Post by coyoteconscious » Sun Nov 03, 2019 6:52 pm

My mission: Allow a user to select an application from an answer file dialog, then assign that application's icon to a button in the app.

The problem:
An application's icon can have an arbitrary icon, and more than one icon icss file can live in the Contents / Resources directory of an application package. The actual bundle icon name can be found in the application's .plist file, but I am unable to access the plist file - they come through garbled and unreadable.

I have even tried making a temporary copy of the .plist file to my stack directory, to read it from there, but no dice.

The .plist files are readable just fine in a text editor or xcode.

I have tried reading them via URL, read from file until EOF, and even for the heck of it tried reading as a binfile and then setting the encoding to utf8.

No dice.
Instead of getting something like :

Code: Select all

<dict>
	<key>Application-Group</key>
	<array>
		<string>dot-mac</string>
		<string>InternetAccounts</string>
	</array>
(etc)...
I either get empty, or I get something like:

Code: Select all

bplist00fl)	
 !"#$%&'()*:;<=>?@B_`>a#$%'()(*+AB£44FGHIJ etc.)...
I am at a loss. I presume this is some sort of encoding issue. The plist file (from Safari, in this example), is in utf8.

I am having no trouble reading other xml files or text files. The only place I am having the problem is with .plist files from application packages.

Stranger, when making a copy of the file, I can sometimes read the file properly _once_, and then if I attempt to read it a second time, I get the above behavior.

Worse, if I do this a few times, the whole stack becomes corrupted, and I have to start over.

I just want to get the path to a darn icon! ; )

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 3816
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Problem reading .plist file inside app package

Post by richmond62 » Sun Nov 03, 2019 7:55 pm

I dunno what's going on with you, BUT . . .

I just did THIS (MacOS 10.14.6, LiveCode 9.5.1 RC-1):

Code: Select all

on mouseUp
   answer file "Choose a pList file to import"
   if the result = "cancel" 
   then exit mouseUp
   else
      set the text of fld "peeList" to URL ("file:" & it)
   END IF
end mouseUp
-
pee.png
-
and it "Cut the Mustard" just as you'd expect. :D

I've deleted the stack file I uploaded here as I've attached a modified version further down.
Last edited by richmond62 on Sun Nov 03, 2019 9:19 pm, edited 1 time in total.

Klaus
Posts: 11314
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Problem reading .plist file inside app package

Post by Klaus » Sun Nov 03, 2019 8:01 pm

Hi coyoteconscious,

welcome to the forum!

Bad news:
1. We are not allowed to write in folder "Applications" on the Mac!
Except on your own machine with Admin permissions, not recommended nevertheless. :D
And even that may end with macOS Catalina, but maybe (hopefully) I am wrong here...

2. We (especially your app) is/are even less allowed** to mess around with other apps plist
or any other files inside of the app package inside of the "Applications" folder.
**You get the picture. :D

Best

Klaus

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 3816
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Problem reading .plist file inside app package

Post by richmond62 » Sun Nov 03, 2019 8:24 pm

We are not allowed

says who?


The ghost of Steve Jobs.

-
Max.jpg
Max.jpg (9.87 KiB) Viewed 614 times
-
I just copied the pList out of Text Edit onto my desktop for that "little demonstration."

There is NOTHING to stop me copying the pList back into the Text Edit app folder after mucking around with it.

Although, admittedly, it may play Merry Hell with my computer. 8)
You get the picture.
-
badlyTuned.jpg
badlyTuned.jpg (9.88 KiB) Viewed 613 times
-
No, I don't because . . .

1. On different wavelength to you. :D

4. After years in authoritarian institutions I never "get the picture," I just draw my own. :twisted:

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 3816
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Problem reading .plist file inside app package

Post by richmond62 » Sun Nov 03, 2019 8:32 pm

My mission: Allow a user to select an application from an answer file dialog, then assign that application's icon to a button in the app.
Why do I feel you might be better to mine an app's package for the .icns resource rather than digging around in the pList?
-
Screenshot 2019-11-03 at 21.31.57.png
-
Mind you, you'll have to be very clever to work out how to import an .icns file:
-
Screenshot 2019-11-03 at 21.41.59.png

coyoteconscious
Posts: 9
Joined: Sun Nov 03, 2019 6:30 pm

Re: Problem reading .plist file inside app package

Post by coyoteconscious » Sun Nov 03, 2019 9:06 pm

richmond62: Yes. And that works _just fine_ if I am not trying to read a plist file that lives inside an application package, that I have created myself. But it does not work when I attempt to read the one inside an app package that says where it's icon lives.

coyoteconscious
Posts: 9
Joined: Sun Nov 03, 2019 6:30 pm

Re: Problem reading .plist file inside app package

Post by coyoteconscious » Sun Nov 03, 2019 9:08 pm

Klaus:
You wrote:
1. We are not allowed to write in folder "Applications" on the Mac!
Except on your own machine with Admin permissions, not recommended nevertheless. :D
And even that may end with macOS Catalina, but maybe (hopefully) I am wrong here...

I am not trying to write to anything at all. I am trying to _read_ a value, so that I can determine the icon file. I am attempting to make a mini-launcher for files and documents, and would like to display the icon without having to manually paste it in, because that would be a little silly. ; ) It is fairly obvious that it is not restricted from reading, because there are eleventy-billion launcher and dock-a-like apps out there that read this information.

coyoteconscious
Posts: 9
Joined: Sun Nov 03, 2019 6:30 pm

Re: Problem reading .plist file inside app package

Post by coyoteconscious » Sun Nov 03, 2019 9:10 pm

richmond62 wrote:
My mission: Allow a user to select an application from an answer file dialog, then assign that application's icon to a button in the app.
Why do I feel you might be better to mine an app's package for the .icns resource rather than digging around in the pList?
That would work, if the icon file were always named the same thing in the same location. Many apps have multiple such files, with different names, and choosing the correct one from the plist is the ideal solution, rather than randomly grabbing the first one listed.

coyoteconscious
Posts: 9
Joined: Sun Nov 03, 2019 6:30 pm

Re: Problem reading .plist file inside app package

Post by coyoteconscious » Sun Nov 03, 2019 9:12 pm

richmond62 wrote:
Sun Nov 03, 2019 8:24 pm

I just copied the pList out of Text Edit onto my desktop for that "little demonstration."
Yep. I can go into the package and copy the file out just fine. And as mentioned in my original post, I can open it in other applications just fine. My problem is that even though it says the file is utf8 encoded, when I attempt to import it into Livecode, it comes out a garbled mess, as if the encoding were wrong.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 3816
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Problem reading .plist file inside app package

Post by richmond62 » Sun Nov 03, 2019 9:19 pm

a garbled mess
As a pList is nothing but a TEXT file, with a fancy suffix,

and, as I seem to be able to manage an import with no garbling, I really wonder what you are doing.

Possibly
I have tried reading them via URL, read from file until EOF, and even for the heck of it tried reading as a binfile and then setting the encoding to utf8.
Over-complicating matters . . . I just looked for a TEXT file. :D No "utf8", no stress, no mess.
-
mleko.png
-
pee2.png
Attachments
pee.livecode.zip
Here's the stack.
(1.24 KiB) Downloaded 17 times

Klaus
Posts: 11314
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Problem reading .plist file inside app package

Post by Klaus » Sun Nov 03, 2019 9:29 pm

Oh, sorry, looks like I completely misunderstood the problem. :oops:
I promise to read everything better next time.

But yes, just reading should work (eventually 8) ).

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 3816
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Problem reading .plist file inside app package

Post by richmond62 » Sun Nov 03, 2019 9:40 pm

But it does not work when I attempt to read the one inside an app package that says where it's icon lives.
That would seem to have nothing to do with LiveCode, but the way MacOS apps
(which, face it aren't really apps, they're fancy folders with all sorts of 'gubbins' inside them pretending to be apps)
are put together on a Macintosh means that one cannot open anything inside an app package from outside, but
only by right-clicking a file from within the app package.

Now, if you can somehow get LiveCode to bypass MacOS's setting that makes an app package look like something
other than the folder it really is you'll manage the thing; but I really don't know how you'll do that.

coyoteconscious
Posts: 9
Joined: Sun Nov 03, 2019 6:30 pm

Re: Problem reading .plist file inside app package

Post by coyoteconscious » Sun Nov 03, 2019 10:00 pm

Maybe an example will help.

Click "Choose App". I have been using Safari as my example app, though I'm getting the same behavior with other apps.

When you choose the app, it will fill in a field showing the path to the app file. Then it fills in a field with the path to the Info plist file within that app package. If you want to verify, go to the app selected in the finder, show package contents, and see that it is showing the path to the Info plist file.

Now, under that, click "Read Values from Plist". It will read the file and put the contents into the big field. Note that it looks like garbage.

Click the other button that says "Read Values from copy of plist" That one makes a _copy_ of the file from inside the app package, into the same directory that the sample stack lives in. You can open that in any text editor and see that it looks normal. But when it imports the contents into the field, voila! Garbage!

Now use the "choose plist" button underneath and select a plist file that you make yourself, or use the sample one included with the stack. When you click the "Read Values from Plist Directly" button, it will put the normal, un-garbaged contents into the field.

Look at the scripts of the buttons and see that I am not doing anything mysterious.

At this point, I am just trying to pull in an application's Info plist file as plain old text so that I can parse it for the appropriate location of the icon file in the package. That's not important here, as I already have a script that parses that stuff out from a well-formed plist field already, and that works fine.

My problem is that the encoding appears to be weird, so it is misinterpreting some characters, like maybe linefeeds or tabs or spaces or something, so I cannot _get_ a well-formed plist file as text.

I am not trying to write a file. I am not trying to change a file. I am not trying to alter the plist or other files within the application bundle. I am just trying to read the plist file inside as text, so I can look up a value or three from it.
Attachments
read-icon-from-plist.zip
(8.39 KiB) Downloaded 15 times

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 3816
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Problem reading .plist file inside app package

Post by richmond62 » Sun Nov 03, 2019 10:23 pm

I did exactly what you suggested and did NOT get garbage:
in fact I got exactly the same sort of thing from a pList inside BBedit with your stack
as I got with my 100 times more primitive stack from a pList outWith a stack:
-
Screenshot 2019-11-03 at 23.20.47.png

coyoteconscious
Posts: 9
Joined: Sun Nov 03, 2019 6:30 pm

Re: Problem reading .plist file inside app package

Post by coyoteconscious » Sun Nov 03, 2019 10:43 pm

richmond62 wrote:
Sun Nov 03, 2019 10:23 pm
I did exactly what you suggested and did NOT get garbage:
in fact I got exactly the same sort of thing from a pList inside BBedit with your stack
as I got with my 100 times more primitive stack from a pList outWith a stack:
-
Hard to tell through text, but you kind of come across as if you are being snide. When someone comes to a forum asking for help, if your goal is anything other than to be helpful, maybe you should not respond.

For instance, if you have a simpler stack that actually works, you could have posted what you did.

When I do it, I get this:
Attachments
Screen Shot 2019-11-03 at 2.42.46 PM.png
Last edited by coyoteconscious on Sun Nov 03, 2019 10:51 pm, edited 1 time in total.

Post Reply

Return to “Mac OS”