sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Mac read_defaults?

    Scheduled Pinned Locked Moved Developers' Forum
    20 Posts 4 Posters 611 Views 4 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S Offline
      slbaumgartner
      last edited by

      @driven said:

      @slbaumgartner said:

      The thing is that the SU API's read/write_default methods are wired specifically to this file. They can not read or write defaults from plists belonging to other apps or from the system in general.
      Steve

      Steve this is in the com.sketchup.SketchUp.20#{Sketchup.version.to_i} plist; that's why I can't understand not being able to read it...

      I looked and found that you are right about this key being there, so I did some poking around and came to the conclusion that the API methods are designed only to deal with two-level entries: (section, variable). If you try to omit one, you get a wrong number of arguments error, and if either is an empty string, you get nothing.

      In the plist file this means there is a dict entry in the Root with the section name, and this dict has a key entry with the variable name. But "NSWindow Frame SketchUpDoc" is a single-level key directly in the Root, with no other enclosing dict. I tried using "Root" as the section, but that didn't work either. It seems that the API methods have no way to write or read a Root-level non-dict entry (whether by design or oversight I don't know...).

      1 Reply Last reply Reply Quote 0
      • D Offline
        driven
        last edited by

        @slbaumgartner said:

        ...I tried using "Root" as the section, but that didn't work either.

        been there, done that, got the post card... [ as we say ]

        @unknownuser said:

        It seems that the API methods have no way to write or read a Root-level non-dict entry (whether by design or oversight I don't know...).

        not sure either, but in the past I have written lots of pref's I couldn't retrieve, although they were written, possibly at root level, honestly can't remember...

        it's been bugging me for years...
        john

        learn from the mistakes of others, you may not live long enough to make them all yourself...

        1 Reply Last reply Reply Quote 0
        • Dan RathbunD Offline
          Dan Rathbun
          last edited by

          Well humor me, and try the Plist Gem here:
          http://rubygems.org/gems/plist
          .. and you no longer have to use %x strings.

          Doc: http://plist.rubyforge.org

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • D Offline
            driven
            last edited by

            @dan,

            result = Plist;;parse_xml("/Users/johns_iMac/Library/Preferences/com.sketchup.SketchUp.2014.plist")
            Error; #<ArgumentError; invalid byte sequence in UTF-8>
            /Users/johns_iMac/Library/Application Support/SketchUp 2014/SketchUp/Gems/gems/plist-3.1.0/lib/plist/parser.rb;91;in `scan'
            

            I don't think its been updated for Ruby 2...

            john

            learn from the mistakes of others, you may not live long enough to make them all yourself...

            1 Reply Last reply Reply Quote 0
            • Dan RathbunD Offline
              Dan Rathbun
              last edited by

              Well if you search Rubygems.org, you'll see quite a few plist reader gems.

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • Dan RathbunD Offline
                Dan Rathbun
                last edited by

                @driven said:

                @dan,

                result = Plist;;parse_xml("/Users/johns_iMac/Library/Preferences/com.sketchup.SketchUp.2014.plist")
                > Error; #<ArgumentError; invalid byte sequence in UTF-8>
                > /Users/johns_iMac/Library/Application Support/SketchUp 2014/SketchUp/Gems/gems/plist-3.1.0/lib/plist/parser.rb;91;in `scan'
                

                I don't think its been updated for Ruby 2...

                It was supposed to be 1.9.x compatible (since it's v3.0.0)

                Try on a simpler plist. Perhaps SketchUp corrupted it's file ?

                I'm not here much anymore.

                1 Reply Last reply Reply Quote 0
                • D Offline
                  driven
                  last edited by

                  I think it's actually failing on the binary image chunks stored in some of the keys...

                  the thing is there are many built in plist tools that can be used in any plugin, on any mac...

                  Gem support from SU Ruby is broken for many things, so I'd favour %x() over failure...

                  result = %x( plutil -p "/Users/johns_iMac/Library/Preferences/com.sketchup.SketchUp.2014.plist") returns a human readable string...

                  point is I only want the one item and it should be available from Sketchup.read_defaults
                  john

                  learn from the mistakes of others, you may not live long enough to make them all yourself...

                  1 Reply Last reply Reply Quote 0
                  • tt_suT Offline
                    tt_su
                    last edited by

                    @driven said:

                    but every concievable version of

                    Sketchup.read_default("NSWindow Frame SketchUpDoc", "")
                    

                    returns nothing...

                    Sketchup.read_default is not a generic method to read anything from a plist. It's a simple method to read simple values for an extension.

                    What you try to do I have done using a shell command (backticks I think). (Don't have the sample snippet on my home machine right now.)

                    1 Reply Last reply Reply Quote 0
                    • Dan RathbunD Offline
                      Dan Rathbun
                      last edited by

                      @driven said:

                      I think it's actually failing on the binary image chunks stored in some of the keys...

                      Well it's Doc did say it would choke on data elements.

                      I'm not here much anymore.

                      1 Reply Last reply Reply Quote 0
                      • D Offline
                        driven
                        last edited by

                        @tt_su said:

                        ...
                        Sketchup.read_default is not a generic method to read anything from a plist. It's a simple method to read simple values for an extension.

                        I haven't ever suggested it reads random plist's, I think the API should be able to read SketchUp's own plist items...

                        @unknownuser said:

                        What you try to do I have done using a shell command (backticks I think).
                        It will be similar to my first, working example, it works with `` or %x(), I just find %x() more obvious when reading the code...

                        john

                        learn from the mistakes of others, you may not live long enough to make them all yourself...

                        1 Reply Last reply Reply Quote 0
                        • S Offline
                          slbaumgartner
                          last edited by

                          @driven said:

                          I think it's actually failing on the binary image chunks stored in some of the keys...

                          The property you sought looks like this in XCode on my Mac:

                          Screen Shot 2014-05-11 at 3.14.04 PM.png

                          It's a string key and value, So I don't think the issue is with binary chunks, it is as TT says simply that read_defaults wasn't designed to read values that weren't written by write_defaults.

                          Steve

                          1 Reply Last reply Reply Quote 0
                          • D Offline
                            driven
                            last edited by

                            @slbaumgartner said:

                            So I don't think the issue is with binary chunks, ...

                            @steve...
                            that comment was referring to the plist gem, it appears to fail on the "BigBrowser" image buttons values that are stored in binary... [but what is BigBrowser??]

                            Now I know it only reads what it can write, I'll continue using defaults for anything else...

                            john

                            learn from the mistakes of others, you may not live long enough to make them all yourself...

                            1 Reply Last reply Reply Quote 0
                            • Dan RathbunD Offline
                              Dan Rathbun
                              last edited by

                              Well on the PC, we have been in the same boat. The API can read only string registry values. Many things are DWORD binary values. Often holding only 1 or 0 for true/false, on/off, etc. Such a simple thing that can not be read.

                              A long time ago, I thought I filed a Feature Request for an application level options hash interface.

                              I'm not here much anymore.

                              1 Reply Last reply Reply Quote 0
                              • 1 / 1
                              • First post
                                Last post
                              Buy SketchPlus
                              Buy SUbD
                              Buy WrapR
                              Buy eBook
                              Buy Modelur
                              Buy Vertex Tools
                              Buy SketchCuisine
                              Buy FormFonts

                              Advertisement