Page 2 of 2

Re: specialFolderPaths("documents") returns empty string on linux LXLE

Posted: Sun Feb 10, 2019 2:39 pm
by FourthWorld
I did indeed; fixed.

Re: specialFolderPaths("documents") returns empty string on linux LXLE

Posted: Sun Feb 10, 2019 3:03 pm
by bogs
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.

Re: specialFolderPaths("documents") returns empty string on linux LXLE

Posted: Sun Feb 10, 2019 6:49 pm
by slowmaker
bogs wrote: Sun Feb 10, 2019 12:17 pm I think he means you, slowmaker :wink:
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

Re: specialFolderPaths("documents") returns empty string on linux LXLE

Posted: Sun Feb 10, 2019 10:02 pm
by bogs
slowmaker wrote: Sun Feb 10, 2019 6:49 pm 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...).
Unfortunately, he mistook you for me, not Klaus, so your out of luck there :twisted:
slowmaker wrote: Sun Feb 10, 2019 6:49 pm 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.
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'.