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

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

FourthWorld
VIP Livecode Opensource Backer
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

Post by FourthWorld » Sun Feb 10, 2019 2:39 pm

I did indeed; fixed.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

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

Post by bogs » Sun Feb 10, 2019 3:03 pm

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.
Image

slowmaker
Posts: 47
Joined: Fri Feb 08, 2019 1:53 pm

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

Post by slowmaker » Sun Feb 10, 2019 6:49 pm

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
The important thing is not to stop questioning. Curiosity has its own reason for existence. - Albert Einstein (LIFE Magazine (1955 may 2), p64)

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

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

Post by bogs » Sun Feb 10, 2019 10:02 pm

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'.
Image

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”