How to get the folder path of Desktop?

I have a problem with how to get the desktop path of the current user.

Groovy Script as below:

String desktop_path ='user.home' + "/Desktop"

How to translate this script into Custom Actions script?

Hi @ShawnLi.
You can read about Custom Script action in this guide:

Hi @Lera,
Thanks for your reply. I try to edit the script as below, but there’s an error.
How to modify it?
output = ‘desktop_path’
def customScript() {
desktop_path =‘user.home’ + “/Desktop”

Can you please show the error message? Also I forgot to mention that you should use double back slash, when you add “Desktop” to the folder - \\Desktop.

Here’s the error message for your reference.
error message.txt (2.1 KB)

Thank you. I see in the error the following exception:
Caused by: java.lang.ClassCastException: Cannot cast java.lang.String to
that means that you need to convert your result from Java String to specific recorder type, in your case this is RString.
Please pay attention to the last line of my script:

    output = 'result_str' // return script result and assign to a Recorder variable
def customScript() {
    def String desktop_path ='user.home' + "\\Desktop"
    result_str = RString.of(desktop_path)

Hi @Lera, It’s very helpful! I’m going to learn how to edit scripts.
Thank you for your time and efforts.


Glad to know that I could help :grinning:. By the way, do you mind if we add your script to Custom Script Code samples?

1 Like

It’s my pleasure. I uploaded the script if anyone need it. (1.0 KB)