Get path to user's desktop

Hi there,

I have a workflow that converts JSON to Excel ( Spreadsheet File node) and then writes the file to my desktop, i.e. /Users/Dick/Desktop/test.xlsx

Now I would like to make this variabel and therefore I need to get the current user’s name or path to his/her desktop.

Is this possible? And if so, how?

Thanks in advance and best regards - Dick

Hi @dickhoning, iirc you were using a Mac for your desktop app, right? I don’t have one myself but you should be able to reference the current users’ home directory with a ~.

So you can probably use ~/Desktop/test.xlsx

Hi Tom, thanks for your fast reply! Unfortunately, this does not work …

Sorry to hear. Maybe @ivov can suggest an alternative for reading the current user’s desktop path via the desktop app on Mac?

Run whoami in Execute Command node and plug it into the full path:

/Users/<username>/Desktop/example.xlsx
1 Like

thanks … that works … I’ve added Execute Command with whoami and use the following expression:

/Users/{{$node[“Execute Command”].json[“stdout”]}}/Desktop/test.xlsx

Can you please also tell how I can make this cross-platform, in other words, make this work on Windows as well … and how to tell whether the workflow gets executed on Mac or Windows?

Thanks again!

1 Like

$env.N8N_DEPLOYMENT_TYPE resolves to desktop_win or desktop_mac

whoami should work on Windows as well iirc

2 Likes

Sounds really cool @dickhoning , congrats! If not sensitive would you mind sharing the workflow? I’m not a dev so these things tend to be over my head but can find it really useful for a personal case I am working on. Does it convert a specific JSON file or does it map any JSON file to excel? Thanks in advance.
Andres

1 Like

Hi Andres, I’m always happy to share what I build! However, the flow is not completely ready yet. I’m still looking for a solution to get the Excel file out via the Respond to Webhook node. In this web hook, I’m getting in JSON via the FileMaker Data API which I then convert to JSON that can be converted by the Spreadsheet File.

the FileMaker JSON looks like this …

{
"response": {
"dataInfo": {
"database": "Vitamines",
"layout": "Vitamine",
"table": "Vitamines",
"totalRecordCount": 369,
"foundCount": 44,
"returnedCount": 44
},
"data": [
{
"fieldData": {
"Productnummer": "test123",
"EAN_barcode": 123456,
"Productnaam": "test one two three ... four ... five",
"Vorm": "rond",
"Aantal_verpakking": "",
"id": 1001815
},
"portalData": {
},
"recordId": "318",
"modId": "5"
},
{
"fieldData": {

@pradilla Hi Andres, here’s a copy of the finished workflow … thanks to @MutedJam