omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Access Pythonista Settings from Script

    Pythonista
    3
    6
    1061
    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.
    • Harum_Scarum
      Harum_Scarum last edited by

      I’d like to write a script that checks the Pythonista settings from within the script. Specifically, I’d like to check the indentation settings - whether they are tabs or spaces, and the number of spaces. I couldn’t find anything on this topic in the documentation or forum, but sorry if I missed something on this topic. Any suggestions on how I might reference this information?

      cvp 2 Replies Last reply Reply Quote 0
      • cvp
        cvp @Harum_Scarum last edited by

        @Harum_Scarum try something like

        import editor
        def main():
        	indent = '?'
        	f = editor.get_text()
        	lines = f.split('\n')
        	for line in lines:
        		if not line:
        			continue
        		if line[0] == '\t':
        			indent = 'tab'
        			break
        		elif line[0] == ' ':
        			n = len(line) - len(line.lstrip())
        			indent = str(n)+ ' blanks'	
        			break
        	print(indent)	
        	
        main()
        
        1 Reply Last reply Reply Quote 0
        • cvp
          cvp @Harum_Scarum last edited by

          @Harum_Scarum sorry, my script finds what you do, not what the setting value is.

          1 Reply Last reply Reply Quote 0
          • JonB
            JonB last edited by

            from objc_util import *
            >>> defaults=ObjCClass('NSUserDefaults').standardUserDefaults()
            >>> defaultsDict=defaults.dictionaryRepresentation()
            >>> defaultsDict['UseSoftTabs']
            <b'__NSCFBoolean': 1>
            >>> defaultsDict['IndentationWidth']
            <b'__NSCFNumber': 3>
            

            type defaultsDict at the console to see all of the pythonista settings that you can check this way.

            cvp 1 Reply Last reply Reply Quote 4
            • cvp
              cvp @JonB last edited by

              @JonB wow

              1 Reply Last reply Reply Quote 0
              • Harum_Scarum
                Harum_Scarum last edited by

                Thank you!

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post
                Powered by NodeBB Forums | Contributors