specialFolderPaths("documents") returns empty string on linux LXLE
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- VIP Livecode Opensource Backer
- Posts: 9842
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: specialFolderPaths("documents") returns empty string on linux LXLE
I did indeed; fixed.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: specialFolderPaths("documents") returns empty string on linux LXLE
Nice bug report
I'll point out here, as I did there, that basic error checking should always be done, even with simple handlers like these.
I'll point out here, as I did there, that basic error checking should always be done, even with simple handlers like these.
Re: specialFolderPaths("documents") returns empty string on linux LXLE
No worries; being mistaken for a long-standing member w/ high post count and useful info is a compliment for a new poster (I hope...). So thanks yourself, FourthWorld.
Below is the first releasable swing at a wrapper to extend specialFolderPath() to handle common Linux folders like Desktop, Downloads, etc. more accurately between now and such time as the built-in might be updated. This has only been tested lightly, so I imagine there are some bumps in the road still to come, edits probable, etc.
This might make more sense as a (tiny, tiny) library, but I'm still so new to livecode I don't even know what livecode's equivalent of libraries, header files, classes, etc. are. So copy-and-paste functions it shall be.
specialFolderPathTMM() is the function you would actually call, e.g. specialFolderPathTMM("documents"). See the comments in its helper, xdgGetPath(), for generic folder names that are likely to work.
Code: Select all
function specialFolderPathTMM pGenericName
# below line is the version you need if your dev environment *is* linux
#if the environment is "linux" or the environment is "development" then
if the environment is "linux" then
put specialFolderPath(pGenericName) into tPath
if the result is "folder not found" or tPath is nothing or pGenericName is "desktop" then
# verify xdg utility exists and is responsive first
if not (xdgGetPath("") ends with "not found") then
put xdgGetPath(pGenericName) into tPath
end if
end if
else
put specialFolderPath(pGenericName) into tPath
end if
return tPath
end specialFolderPathTMM
function xdgGetPath pCommonFolderName
# get common user directory paths on Linux.
# BEHAVIOR UNDEFINED ON NON-LINUX; it could just as easily cook your goldfish
# with a weasel patty on the side as produce usable output in those other OSes
# (depends on weasel patty patch status in posix sub-system).
# as of 2019 feb 10, common linux user folder names supported by xdg-user-dir are:
# DESKTOP, DOWNLOAD, DOCUMENTS, VIDEOS, PICTURES, MUSIC,
# PUBLICSHARE, TEMPLATES
# xdg-user-dir should be on any linux distro that uses systemd as a system manager,
# plus possibly others.
# If xdg-user-dir is not on the system, you'll get an error message in the return,
# which should end with "not found".
# If the folder name submitted is not valid or not defined, you just get
# the user folder by default.
put shell("xdg-user-dir " & toUpper(pCommonFolderName)) into tShellMessage
replace return with empty in tShellMessage
return tShellMessage
end xdgGetPath
The important thing is not to stop questioning. Curiosity has its own reason for existence. - Albert Einstein (LIFE Magazine (1955 may 2), p64)
Re: specialFolderPaths("documents") returns empty string on linux LXLE
Unfortunately, he mistook you for me, not Klaus, so your out of luck there
Not so much different from other languages as you might think, and code reuse is always a good thing imho. The nice thing is, if you really wanted, you could stick *all* (although I don't) your go to code into one stack and that is your 'library'.