Finding folder/files in the application folder

Deploying to Mac OS? Ask Mac OS specific questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

jmk_phd
Posts: 213
Joined: Sat Apr 15, 2017 8:29 pm

Finding folder/files in the application folder

Post by jmk_phd » Tue Nov 12, 2019 1:25 am

My program is located in a folder (dubbed EAS-SABE) in the Mac Applications folder. In turn, this includes a subfolder containing numerous audiofiles, along with several text files needed to lookup the results.

The routine to identify the path to that program folder -- and, consequently, to the items included within it -- works just fine in the standalone using my default macOS Snow Leopard, in macOS Sierra, and in the Windows version.

However, my Mac beta-testers are reporting that my app warns that none of the items included in the program folder are available. (At least one tester reports running macOS Mojave.) Has something changed in how we identify the folder containing the standalone?

Here's one handler -- called from preOpenStack -- that worked previously to identify the path to the audiofile folder:

Code: Select all

on doStoreAudioPath -- UPDATED WITH SPANISH WARNING
   local tStackPath -- full path to the stack
   -- get stack folder
      put the effective filename of stack "EAS_SABE" into tStackPath
      set the itemDelimiter to slash
      if the platform = "MacOS" and the environment = "standalone application" then
         -- if this is a standalone application running on a Mac, find the path to the .app file
         repeat until last item of tStackPath contains ".app"
            delete last item of tStackPath
         end repeat
      end if
      -- remove last item to get the path to the containing folder
      delete last item of tStackPath
      set the cFolderPath of stack "EAS_SABE" to tStackPath
      -- create and store path to audiofile folder
      put tStackPath & slash & "EAS_Audiofiles" into tAudioPath
      -- confirm that the Audiofile folder exists
      if there is a folder tAudioPath then -- folder exists
         set the cAudioPath of stack "EAS_SABE" to tAudioPath
      else -- folder cannot be found, so warn in both english and spanish
         switch
            case the cVersion of stack "EAS_SABE" = "EAS"
               answer warning "Audiofile folder cannot be found."
               break
            case the cVersion of stack "EAS_SABE" = "SABE"
               answer warning "No se encuentra el directorio de las grabaciones auditivas."
               break
         end switch
         set the cAudioPath of stack "EAS_SABE" to empty
      end if
end doStoreAudioPath
Apparently, there is something wrong here, owing to some change introduced after macOS Sierra.

Please correct me, so I can inform my very patient beta-testers.

Thanks. jeff k

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

Re: Finding folder/files in the application folder

Post by bogs » Tue Nov 12, 2019 1:44 am

Mind you, I'm not 'Mac' centric, but Klaus continually mentions this kind of thing. I think the problem is the way that Mac handles 'app' folders. I *believe* the solution is not to build your own path to it, i.e. -

Code: Select all

   -- get stack folder
      put the effective filename of stack "EAS_SABE" into tStackPath
      set the itemDelimiter to slash
      if the platform = "MacOS" and the environment = "standalone application" then
         -- if this is a standalone application running on a Mac, find the path to the .app file
         repeat until last item of tStackPath contains ".app"
            delete last item of tStackPath
         end repeat
      end if
Instead, you would use "specialFolderPath" and either -
Engine - The folder containing the engine and the executable files copied in the standalone application.
-or-
Resources - In development mode, the current stack folder. In a standalone, the resources folder where non-executable files, or folders specified from the Standalone Builder, are copied.

I believe he recommends the 2nd, or better yet putting things like that in to spf(documents). Maybe he'll chime in :D
Image

jmk_phd
Posts: 213
Joined: Sat Apr 15, 2017 8:29 pm

Re: Finding folder/files in the application folder

Post by jmk_phd » Tue Nov 12, 2019 5:59 pm

bogs --

Thanks for reply. I did indeed employ the code you quoted, which was borrowed from a LiveCode lesson:

http://lessons.livecode.com/m/4071/l/78 ... resides-in

This has worked fine across several of my LC standalones (at least through macOS Sierra) until now. One Mac beta-tester recruited by my client still reported no problem, whereas the other two did. At least one of the latter was running the more recent macOS Mojave, which leads me to suspect that Apple's recent changes to its file system may have broken the original strategy.

Of course, instead of simply warning that the folder containing the 354 MB of audiofiles (approx. 750 .wav files) could not be found, one quick-and-dirty workaround would be to prompt the user to identify that folder manually via an answer folder dialog. However, forcing the user to do so each time the standalone is launched is unacceptable, as is forcing the user to identify manually each of the three tiny .txt files needed in order to score the results.

Klaus did provide some time ago a very useful code snippet -- employing "specialFolderPath" -- that I've used to store and retrieve preferences files.

I will try to create a standalone employing the specialFolderPath "resources" just to see the result. However, it is not an option to include 354 MB of audiofiles into a standalone build -- which would make downloading program updates onerous. Moreover, the tiny .txt files used to score the results must be updated frequently, so these ought not to be incorporated into the standalone.

I'll post here the results of the specialFolderPath "resources" experiment.

jeff k

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Finding folder/files in the application folder

Post by FourthWorld » Tue Nov 12, 2019 7:54 pm

I would not download anything into the app folder. Apps are normally in protected space requiring elevated privileges for writes.

Use a user-writable folder within the user's home for that.

IIRC, "~/Library/Application Support" seems to be the most commonly used, and prescribed, location for downloaded resources.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

jmk_phd
Posts: 213
Joined: Sat Apr 15, 2017 8:29 pm

Re: Finding folder/files in the application folder

Post by jmk_phd » Tue Nov 12, 2019 11:11 pm

Hi Richard --

You're right, of course, that an app should write nothing to the Applications folder. (Some time back I had a tussle with my Windows-centric client, who'd been used to having his VisualBasic app write files to the Applications directory. I won that argument.)

The documents generated by my apps are written to a subfolder created in the user's Documents folder -- or, in the case of alterable preferences files, to the user's Prefs folder -- using the model code published a few years ago by Klaus, to which Bogs alluded.

I really dislike apps that "phone home" for updates, so I'd never do that. But (unless things have changed with macOS Catalina) users still can download updated files from a website to their Downloads folder with permission to copy/substitute these into the Applications program subfolder.

The question is whether Apple's recent changes to the macOS has rendered invalid the original strategy for identifying the folder enclosing a standalone LC app.

jeff k

jmk_phd
Posts: 213
Joined: Sat Apr 15, 2017 8:29 pm

Re: Finding folder/files in the application folder

Post by jmk_phd » Wed Nov 13, 2019 9:50 am

In response to bogs' worthy suggestion to try employing the specialFolderPath function, as far as I can tell there is no advantage over the code snippet in the original LC lesson about finding the path to the folder containing a standalone. Similar to working with the effective filename of the standalone, both specialFolderPath("engine") and specialFolderPath("resources") require the same acrobatics -- namely, deleting each last item in the path until one reaches the .app file, then deleting that to get the path to the enclosing folder.

Of course, something involving application bundles may have changed with Apple's revision of the macOS file system for Mojave and Catalina. Unfortunately -- unlike the Mac beta-testers -- I'm unable to run these latest systems, so I can't test out that hunch.

Hoping that someone in this forum who's already using one of these latest versions of macOS can confirm whether this is a new file system problem.

jeff k

P.S. I have no personal contact with the Mac beta-testers -- college students recruited by my client -- who reported the problem, so it's not inconceivable that they screwed up something. Still, that seems unlikely, inasmuch as installing the program folder was simply a matter of unzipping that folder in their Downloads folder and copying it to the Applications folder. Windows users have reported no problem, nor did one of the three Mac beta-testers.

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

Re: Finding folder/files in the application folder

Post by bogs » Wed Nov 13, 2019 11:15 am

jmk_phd wrote:
Wed Nov 13, 2019 9:50 am
In response to bogs' worthy suggestion to try employing the specialFolderPath function, as far as I can tell there is no advantage over the code snippet in the original LC lesson about finding the path to the folder containing a standalone. Similar to working with the effective filename of the standalone, both specialFolderPath("engine") and specialFolderPath("resources") require the same acrobatics -- namely, deleting each last item in the path until one reaches the .app file, then deleting that to get the path to the enclosing folder.
I am guessing I don't understand what your shooting for, somehow. The 'specialFolderPath("Engine")' shouldn't require *any* path acrobatics, it should take you directly to the folder containing the engine and the executable files. If your looking for a file or folder in the folder the engine is in, you would not delete anything, you would instead add the missing thing, in this case let's say folder of audio files named "myAudioFiles", the line would look like this (psuedo code) -

Code: Select all

set the folder to specialFolderPath("Engine") & "/myAudioFiles"
put the files
Of course, you still need to test whether you are in the IDE or not, in the ide, the 'engine' is the actual Lc installed folder, as you can see here -
ksnip_sfp1.png
I've arrived !
If I then wanted to see what is inside 'resources', I'd simply add it to the path -
ksnip_sfp2.png
A day late and a dollar short...
The 'advantage' to the special folder path series (to me) is that you are using less code to do the same thing as getting the path to the exe, setting delimiters, subtracting items, etc etc etc and of course, it is universal currently to all of the Os'es.

This was what I thought you were looking for, but I will add that I firmly believe putting anything into the engine folder is a mistake, and especially on Mac. Using the documents folder, or the resources folder, or what Richard said, is the far better route.
Image

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Finding folder/files in the application folder

Post by Thierry » Wed Nov 13, 2019 12:43 pm

jmk_phd wrote: In response to bogs' worthy suggestion to try employing the specialFolderPath function, as far as I can tell there is no advantage over the code snippet about finding the path to the folder containing a standalone.
Hi Jeff,

I am with you on this one; spicyFolderPath() is just syntaxic sugar;
handy but not mandatory.
Plus, I can't believe this has something to do with your problem.
Hoping that someone in this forum who's already using one of these latest versions of macOS can confirm whether this is a new file system problem.
If you feel so, I can test your app on Mojave for free... up to you.


Regards,

Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

jmk_phd
Posts: 213
Joined: Sat Apr 15, 2017 8:29 pm

Re: Finding folder/files in the application folder

Post by jmk_phd » Wed Nov 13, 2019 8:16 pm

Hi bogs --

Although what you say is true when working with the IDE, my issue is instead with the standalone distributed to users.

The standalone is distributed in a .zipped folder. When the folder is unzipped and copied to the Applications folder, it's like this:

HD
..Applications
....EAS folder
......EAS_Audiofiles [a folder containing .wav files]
......EAS-SABE [the standalone application]
......EAS_norms.txt [a text file read into memory at startup]

The aim is to get the path to the enclosing "EAS folder", to which "/EAS_Audiofiles" or "/EAS_norms.txt" can be appended.

Using specialFoldersPath() has no advantage over the original code (which worked from the effective filename of the app) because the results are similar. When I create a simple standalone with buttons to answer with the result of each strategy, I find this:

effective filename : /Applications/EAS folder/EAS-SABE.app/Contents/MacOS/EAS-SABE
sFP("engine") : /Applications/EAS folder/EAS-SABE.app/Contents/MacOS
sFP("resources") : /Applications/EAS folder/EAS-SABE.app/Contents/Resources/_MacOS

In each case, one still must delete each last element of the path (up to and including EAS-SABE.app) -- the routine to which I referred as "acrobatics" -- in order to get the path to the enclosing folder -- after which on appends "/EAS_Audiofiles" for the path to that folder and "/EAS_norms.txt" for the path to the text file.

jeff k

jmk_phd
Posts: 213
Joined: Sat Apr 15, 2017 8:29 pm

Re: Finding folder/files in the application folder

Post by jmk_phd » Wed Nov 13, 2019 8:52 pm

Thierry --

Thank you for your incredibly kind offer. Although I'm skeptical of recent changes to the macOS file system, I agree that it seems implausible that so basic a routine as the one discussed would fail with a macOS update. I'm just handicapped by not being able to run a macOS beyond Sierra, under which my app still worked just fine.

As mentioned in a previous note, I currently have no direct contact with the three college students recruited as Mac beta-testers by my client (who is still a professor at the university where I'd taught for over 25 years). Although younger persons are often more tech-savvy, it's still possible that the two out of three who've experienced the problem had done something wrong. (Yet one out of three Mac beta-testers has not experienced any problem, nor have those using the Windows version.)

I will try to obtain contact information in order to learn more from those student Mac beta-testers who've reported the problem. If I cannot identify any error that they've made, I may ask you to try out a severely pared-down version of my app that should take only a few minutes to download and run under Mojave.

Thanks so much!

jeff k

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Finding folder/files in the application folder

Post by Thierry » Thu Nov 14, 2019 5:41 am

jmk_phd wrote: Thierry --
Thank you for your incredibly kind offer.
You're welcome.
I'm only trying to do to others what I would like them to do for me, nothing more.

....
I may ask you to try out a severely pared-down version of my app
that should take only a few minutes to download and run under Mojave.
Try to stay as close as your original app for better test results.

I have a couple of thoughts concerning your problem
because some weeks ago, I had to deal with some sort of same behavior.
One of my app was working fine on many systems since a long time,
but somehow partly failed on Mojave and failed differently on Catalina.
So one app, 3 MacOs versions and 3 behaviors :roll:

**** Thanks a lot again for these 2 gentle men who did the testings and report! ***

Kind regards,

Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

jmk_phd
Posts: 213
Joined: Sat Apr 15, 2017 8:29 pm

Re: Finding folder/files in the application folder

Post by jmk_phd » Thu Nov 14, 2019 10:02 pm

Thierry --

You wrote:
I have a couple of thoughts concerning your problem
because some weeks ago, I had to deal with some sort of same behavior.
One of my app was working fine on many systems since a long time,
but somehow partly failed on Mojave and failed differently on Catalina.
So one app, 3 MacOs versions and 3 behaviors
Your experience seems really important for those of us who create macOS standalones. (I'm assuming that your broken apps were written in LC.) Perhaps you've reported on this elsewhere -- I've not yet searched our LC forums to check this out, but I'd be interested in the details. Apart from the obvious 32- vs. 64-bit issue, we need to know how to keep our standalones current with changes to the macOS.

In fairness to LC, I'm still using on a daily basis 8.10 (the last version that runs on Snow Leopard). I did try running LC 9.x in Sierra, but it threw an error for an entirely innocuous looped routine that had worked just fine in 8.10. So I just went back to 8.10.

Perhaps the folks developing LC 9.x already have addressed these issues -- which is hard work, given Apple's changes to the macOS.

jeff k

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Finding folder/files in the application folder

Post by Klaus » Thu Nov 14, 2019 10:16 pm

Hi Jeff,

if you add your Audifiles folder and whatnot via the "Copy files" in the "Standalone Application Settings"
you will find everything in the resulting standalone here -> specialfolderpath("resources")
On EVERY platform, and even in the IDE!!
In the IDE it points to the folder where the current stack lies in.

So you just neet to:

Code: Select all

...
put specialfolderpath("resources") & "/EAS_Audiofiles" into tAudioFolder
...
put specialfolderpath("resources") & "/EAS_norms.txt" into tTextFile
...
We are not allowed to write in (download file to) the "Applications" folder.
Use -> specialfolderpath("preferences")
or -> specialfolderpath("asup") ## = Library/Application Support
to download files for your app.


Best

Klaus

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

Re: Finding folder/files in the application folder

Post by bogs » Thu Nov 14, 2019 10:41 pm

See ? I knew Klaus had answered this before, I just forgot the 'copy files' part of it.

For what it is worth, I agree with Thierry, as well, but I've seen some pretty strange things going on in Mac-land the last several years with folder permissions (why I stopped looking at the OS after 10.6.x). And sure, the sfp commands are just sugar and do the same thing, but so are so many of the other commands and functions. Basically, I consider them quick shots at the more drawn out way of doing it.

Of course, as far back as I am in engines, none of those help me in the least :D

I also know now that I completely mis-understood your intention, I thought you were just trying to get to a folder next to the folder that held the executable, not 3 levels up from there.
Image

jmk_phd
Posts: 213
Joined: Sat Apr 15, 2017 8:29 pm

Re: Finding folder/files in the application folder

Post by jmk_phd » Fri Nov 15, 2019 5:30 am

Klaus --

I understand what you're saying, but it's not welcome news.

Of course I could add the Audiofiles folder and three text files to the standalone resources via "Copy files" in "Standalone Application Settings." But this will bloat the standalone to nearly 260 MB, which for many users is a ridiculously large file to download when it is just an update.

Up at least through macOS Sierra, the user has permission to substitute updated files to the application's subfolder. (These typically never exceed 15 MB and may be as little as a few KB.)

What I've learned from by macOS beta-testers is that my program worked okay in macOS Mavericks and (in my own testing) through Sierra, but apparently broke in High Sierra and Mojave.

Why can't LC figure out a way to identify the path to the folder that encloses a macOS standalone?

jeff k

Post Reply

Return to “Mac OS”