开发者

How to obtain the path of Desktop in gnome

开发者 https://www.devze.com 2023-01-28 18:32 出处:网络
I am using gnome/Ubuntu-10.10 in Chinese language and the desktop path is not \"~/Des开发者_StackOverflowktop\" but \"~/XXXX\" where XXXX stands for the Chinese translation of \"Desktop\". So, how to

I am using gnome/Ubuntu-10.10 in Chinese language and the desktop path is not "~/Des开发者_StackOverflowktop" but "~/XXXX" where XXXX stands for the Chinese translation of "Desktop". So, how to write code to obtain the proper path of desktop regardless of the system language? I noticed Qt SDK properly added a shortcut on the desktop so I guess there is a way. Thanks a lot!


One more way to do it:

dir=$(xdg-user-dir DESKTOP)


The locations of the user directories are described in the xdg-user-dirs specification. They provide some code here that you can copy, to look up the name of the desktop directory from within your code.


If you are using Glib, you can do

const char *desktop_dir = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);

This properly pays attention to the XDG environment variables and all that.


echo ${XDG_DESKTOP_DIR:-$HOME/Desktop}

works fine on a local linux drive and also when the /home/<user> is mapped to an nfs drive.


I have not tested yet, but try echo echo ${XDG_DESKTOP_DIR:-$HOME/Desktop}, this cmd maybe do the work.


The answer is provided by xdg-user-dirs specs:

test -f ${XDG_CONFIG_HOME:-~/.config}/user-dirs.dirs && source ${XDG_CONFIG_HOME:-~/.config}/user-dirs.dirs
echo ${XDG_DESKTOP_DIR:-$HOME/Desktop}
echo ${XDG_DOWNLOAD_DIR:-$HOME}
0

精彩评论

暂无评论...
验证码 换一张
取 消