Computing %PRODUCTNAME user profile and shared modules system file paths can be performed with Python or with Basic languages. BeanShell, Java, JavaScript and Python scripts locations can be derived from this information.
Examples:
With Python shell.>>> from <the_module> import Session>>> print(Session.SharedPythonScripts()) # static method>>> print(Session().UserName) # object property>>> input(Session().UserProfile) # object property
From ... menu.
from <the_module> import Sessiondef demo_session(): import screen_io as ui ui.MsgBox(Session.Share(),title='Installation Share') # static method ui.Print(Session.SharedPythonScripts()) # static method s = Session() # instance creation ui.MsgBox(s.UserName,title='Hello') # object property ui.Print(s.UserPythonScripts) # object propertyg_exportedScripts = (demo_session,) # public macros
With %PRODUCTNAME Basic.
Sub Session_example() Dim s As New Session ' instance of Session class Print "Shared scripts location:", s.SharedScripts MsgBox s.UserName,,"Hello" Print s.UserScripts, Chr(13), s.UserPythonScriptsEnd Sub ' Session_example
Using COM/OLE and Visual Basic Scripting language.
' The service manager is always the entry point' If there is no office running then an office is started upSet sm = WScript.CreateObject("com.sun.star.ServiceManager")' PathSubstitution service exhibits information to infer' <UserProfile|Share>/Scripts/python locations fromSet obj = sm.createInstance("com.sun.star.util.PathSubstitution")MsgBox CreateObject("WScript.Network").UserName,, "Hello"user = obj.getSubstituteVariableValue("$(user)")MsgBox user & "/Scripts",, "User scripts location"libO = Replace(obj.getSubstituteVariableValue("$(inst)"), "program/..", "Share")MsgBox libO & "/Scripts",, "Shared scripts location"
Option ExplicitOption CompatibleOption ClassModulePrivate _ps As Object ' Private memberPrivate Sub Class_Initialize() GlobalScope.BasicLibraries.LoadLibrary("Tools") Set _ps = CreateUnoService("com.sun.star.util.PathSubstitution")End Sub ' ConstructorPrivate Sub Class_Terminate() _ps = NothingEnd Sub ' DestructorPublic Property Get SharedScripts() As String Dim inst As String, shr As String inst = ConvertFromURL(_ps.getSubstituteVariableValue("$(prog)")) shr = Tools.Strings.ReplaceString(inst,"Share","program") SharedScripts = shr & GetPathSeparator() &"Scripts"End Property ' Session.sharedScriptsPublic Property Get SharedPythonScripts() As String sharedPythonScripts = sharedScripts() & GetPathSeparator() &"python"End Property ' Session.sharedPythonScriptsPublic Property Get UserName() As String ' User account name userName = _ps.getSubstituteVariableValue("$(username)")End Property ' Session.userNamePublic Property Get UserProfile() As String ' User profile system path userProfile = ConvertFromURL(_ps.getSubstituteVariableValue("$(user)"))End Property ' Session.userProfilePublic Property Get UserScripts() As String ' User scripts system path userScripts = userProfile() & GetPathSeparator() &"Scripts"End Property ' Session.userScriptsPublic Property Get UserPythonScripts() As String ' User Python scripts system path userPythonScripts = userScripts() & GetPathSeparator() &"python"End Property ' Session.userPythonScripts