Direct Path for Desktop without Usernames for Blender 2.79 thanks for the help on my last question.
Now, i want to export to the desktop path of users, without knowing the username.
I try to explain
Export on Desktop
bpy.context.scene.render.filepath = &quot;/users/luki-krew/desktop/&quot;

Is working for me, the file get saved as 0001.svg on desktop.
But i want something like:
bpy.context.scene.render.filepath = &quot;~/Desktop/0001.svg&quot;

Perfect would be if the file name could be the same like the imported 3d Model. WOULD BE PERFECT !
Like the files named car.fbx - the export should be named car.svg
Than you so much for helping me!
The script below retrieves the home directory and generates the path to the desktop. If the project has been saved before, it adds the name as prefix.

import bpy
import os 
from pathlib import Path
from sys import platform

home_dir = str(Path.home())

if platform == 'linux' or platform == 'win32' or platform == 'darwin':
    desktop_dir = os.path.join(home_dir, 'Desktop')
else:
    raise RuntimeError("OS not supported")

if bpy.data.is_saved:
    filename = os.path.splitext(bpy.path.basename(bpy.data.filepath))[0]
    output = os.path.join(desktop_dir, filename)
else:
    # Project file hasn't been saved before, therefore no filename is available
    output = desktop_dir

bpy.context.scene.render.filepath = output




If you want the prefix to be the same as the active object in the scene:

import bpy
import os 
from pathlib import Path
from sys import platform

home_dir = str(Path.home())

if platform == 'linux' or platform == 'win32' or platform == 'darwin':
    desktop_dir = os.path.join(home_dir, 'Desktop')
else:
    raise RuntimeError("OS not supported")

if bpy.app.version &lt; (2, 80, 0):
    filename_prefix = bpy.context.scene.objects.active.name
else:
    filename_prefix = bpy.context.view_layer.objects.active.name

output = os.path.join(desktop_dir, filename_prefix)
bpy.context.scene.render.filepath = output