Identificar el sistema operativo

Es posible identificar el sistema operativo a través de los lenguajes Python y Basic.

Mediante una clase de Python:


        """ the_module """
        import os, platform
        class Platform():
            @property
            def ComputerName(self): return platform.node()
            @property
            def DirSeparator(self): return os.sep
            @property
            def isLinux(self): return (self.OSName=='Linux')
            @property
            def isMacOSX(self): return (self.OSName=='Darwin')
            @property
            def isWindows(self): return (self.OSName=='Windows')
            @property
            def OSName(self): return platform.system()
            @property
            def PathDelimiter(self): return os.pathsep
    

Mediante un módulo de clase de Basic:

Icono de consejo

LibreOfficeDev BASIC no cuenta con reconocimiento nativo de macOS. La identificación de la plataforma es posible mediante la interfaz de programación de aplicaciones (API) de LibreOfficeDev.



        ''' Module name: Platform '''
        Option Compatible
        Option ClassModule
        Option Explicit
        
        Public Property Get ComputerName As String
            If isWindows Then ComputerName = Environ("ComputerName")
        End Property ' Platform.ComputerName
        
        Public Property Get DirSeparator As String
            DirSeparator = GetPathSeparator()
        End Property ' Platform.DirSeparator
        
        Public Property Get IsLinux As Boolean
            isLinux = ( GetGUIType()=4 ) ' Applies to macOS as well 
        End Property ' Platform.isLinux
        
        Public Property Get IsMacOSX As Boolean
            isMacOSX = ( OSName="MAC" )
        End Property ' Platform.isMacOSX
        
        Public Property Get IsWindows As Boolean
            isWindows = ( GetGUIType()=1 )
        End Property ' Platform.isWindows
        
        Public Property Get OSName As String
            ' Devuelve el nombre de la plataforma como «MAC», «UNIX», «WIN»
            ' Inferido de la función «Tools.UCB.ShowHelperDialog»
            With GlobalScope.Basiclibraries
                If Not .IsLibraryLoaded("Tools") Then .LoadLibrary("Tools")
            End With
            Dim keyNode As Object ' com.sun.star.configuration.ConfigurationAccess
            keyNode = Tools.Misc.GetRegistryKeyContent("org.openoffice.Office.Common/Help")
            OSName = keyNode.GetByName("System")
        End Property ' Platform.OSName
        
        Public Property Get PathDelimiter As String
            Select Case OSName
                Case "MAC", "UNIX" : PathDelimiter = ":"
                Case "WIN" : PathDelimiter = ";"
             End Select
        End Property ' Platform.PathDelimiter
    
Icono de nota

ComputerName environment variable is solely available for Windows. Basic calls to Python macros help overcome LibreOfficeDev Basic limitations.


Ejemplos:

Con Python

>>> from < the_module > import Platform

>>> print(Platform().isMacOSX) # propiedad de objeto

True

>>> input(Platform().OSName) # propiedad de objeto

Darwin

Desde el menú Herramientas ▸ Macros ▸ Ejecutar macro.


        from < the_module > import Platform
        import screen_io as ui
        p = Platform()
        ui.MsgBox(''.join(['isMacOS: ',str(p.isMacOSX)]),0,p.OSName)
    

Con LibreOfficeDev Basic


        Sub Platform_example()
            Dim p As New Platform ' instancia de la clase Platform
            MsgBox p.isLinux ' propiedad de objeto
            Print p.isWindows, p.OSName ' propiedades de objeto
        End Sub ' Platform_example
    
Icono de consejo

• ScriptForge.Platform service provides a collection of properties about the current execution environment and context, that include platform detection.

• Extensive operating system name identification is available from INFO("system") Calc formula.


¡Necesitamos su ayuda!

¡Necesitamos su ayuda!