How to get the folder path of Desktop?

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

Groovy Script as below:

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

How to translate this script into Custom Actions script?

Hi @ShawnLi.
You can read about Custom Script action in this guide: https://kb.workfusion.com/display/RPAe/Script+as+Custom+Action.

Hi @Lera,
Thanks for your reply. I try to edit the script as below, but there’s an error.
How to modify it?
@CustomScriptAction(
output = ‘desktop_path’
)
def customScript() {
desktop_path = System.properties.‘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 com.workfusion.studio.rpa.recorder.api.types.RDataType
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:

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

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

2 Likes

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.
GetDesktopPath.zip (1.0 KB)

2 Likes