Identifying App folder Redux

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

Identifying App folder Redux

Post by jmk_phd » Thu Jan 30, 2020 4:25 am

Back in November 2019, forum member Hermann provided a very elegant snippet of code to identify the path to the subfolder in the Mac Applications folder that contained my standalone (EAS-SABE.app) and supporting files:

Code: Select all

put the effective filename of this stack into eF
put char 1 to offset("EAS-SABE.app",eF)-1 of eF into f0
This identification of the enclosing folder (f0) worked like a charm back in November in identifying the path to the app subfolder in the Applications folder. Moreover, Hermann reported that this worked even when tested in an earlier version of macOS Catalina.

However, it appears that this code is again broken: It no longer identifies the path to the application's enclosing folder.

My short-term solution when the aforementioned code fails to yield a valid path may be to employ a dialog that asks the user to identify the application subfolder manually, so the path can be saved to a custom mainstack prop. (If writing to the user Preferences folder is still allowed in macOS Catalina, I might save this as a text file and retrieve the path upon the next startup.)

Still, I'm utterly perplexed by recent changes to the macOS that might involve the new APFS file system, including those that might be affected by hardware that employs a SSD. I welcome learning of any pitfalls that other LC programmers have encountered.

Thanks much!

jeff k

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7215
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Identifying App folder Redux

Post by jacque » Thu Jan 30, 2020 8:04 pm

Does this work? (Untested)

Code: Select all

set the itemdel to slash
put item 1 to -4 of specialfolderpath("engine")
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

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

Re: Identifying App folder Redux

Post by jmk_phd » Fri Jan 31, 2020 12:02 am

Hi Jacque --

My fault for not providing the full snippet, which would've shown that the issue involved a Mac standalone:

Code: Select all

put the effective filename of stack "EAS-SABE" into tStackPath
   if the platform = "MacOS" and the environment = "standalone application" then
      put char 1 to offset("EAS-SABE.app",tStackPath)-1 of tStackPath into tFolderPath
   else -- must be Windows or IDE
      set the itemDelimiter to slash
      delete last item of tStackPath
      put tStackPath into tFolderPath
   end if
I'd lifted the original code from the LC tutorial "How can I get the path to the folder a stack file resides in?" It worked just fine through macOS Sierra, but users reported last November that it broke in macOS High Sierra and Mojave. Forum member Hermann recommended a more elegant alternative (line 3 of the above snippet). This did in fact resolve the problem in High Sierra and Mojave.

Hermann had reported that this worked even in Catalina, but a new user running Catalina just complained that it was again broken -- i.e., that the folder enclosing the standalone and its support files (stored in the /Applications folder) could not be found.

I'd jumped initially to the conclusion that this might be due to some change involving Apple's new APFS. There is another possibility, of course, which I can't rule out: namely, that this new problem can be traced to the fact that I'm still developing the app and creating (64-bit) Mac standalones using LC Indy 8.10, simply because LC Indy 9.x does not run on my preferred day-to-day macOS Snow Leopard. (I do have Indy 9.5.1 installed on a partition running macOS Sierra, but I'm aware that once I start modifying the code in LC 9.x, there's no going back.) Perhaps the LC folks already have addressed this issue in testing with newer versions of macOS.

I've just taken a call from my client -- a long-time Windows-centric colleague -- freaked out that some of his grad students here in the U.S. (those with newer Macs running Catalina) are unable to use the program. He expressed buyer's remorse over the fact that I'd persuaded him to make available Mac as well as Windows versions of his app -- without understanding that, apart from the few lines of Mac-specific code illustrated above, the only additional cost incurred was the several minutes needed to create a Mac standalone along with a Windows standalone . (He claims that in his eventual target market -- Latin America and Spain -- the macOS is nearly unknown.)

In order to promise him a simple (albeit, from my perspective, less than ideal) solution, I agreed to embed the 740 audio (.wav) files (totaling 250 MB) into a substack -- thereby obviating the need to identify the path to the program folder. Modifying the code probably requires more work than fixing the original problem, but the client is the boss.

Please educate me if there is better alternative that will work through upcoming changes to the macOS. Thanks!

jeff k

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7215
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Identifying App folder Redux

Post by jacque » Fri Jan 31, 2020 12:52 am

The snippet I posted was for Mac OS X, and should find its way backwards from inside the app bundle until it resolves the enclosing folder. I don't have Catalina installed, but theoretically it should work. Maybe someone with Catalina could try it. It did work to find the enclosing folder of the LC app in Mojave when I ran it from the message box.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

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

Re: Identifying App folder Redux

Post by jmk_phd » Sat Feb 01, 2020 3:33 am

Jacque --

Your solution worked like a charm, of course. Tested here it through macOS Sierra, which by your account also works at least through Mojave. I'm just awaiting word back from the student for whom the app broke in Catalina and from one who runs Windows. I'll update here what they report.

Using specialFolderPath("engine") is far more elegant than the strategy I'd borrowed from the LC tutorial -- which, in fairness, may have been written before this function worked with macOS and Windows. Apparently we've got the brilliant folks at LiveCode to thank for saving us from workarounds that break each time an OS is updated.

And thanks especially to you for yet again having been so helpful and supportive.

jeff k

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

Re: Identifying App folder Redux

Post by bogs » Sat Feb 01, 2020 11:18 am

jmk_phd wrote:
Sat Feb 01, 2020 3:33 am
Using specialFolderPath("engine") is far more elegant than the strategy I'd borrowed from the LC tutorial --
Hmmm, where have I read that before Image... WHAAAaaaa ?!?! Image
bogs wrote:
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...
<sic>
...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.
Is this thing on ?!? Image

(Just kidding, Jacque, I'm glad you could explain it better than I Image )
Image

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

Re: Identifying App folder Redux

Post by jmk_phd » Sat Feb 01, 2020 4:30 pm

bogs --

I am rightly chastened for having overlooked the solution you offered back in November 2019 -- essentially the same as Jacque has posted here. My only (lame) defense is having followed the (now obviously) outdated LC tutorial as gospel.

I will be more circumspect -- and more dedicated to due diligence -- in posting questions. Forum members have provided invaluable solutions for me on several occasions over the past few years, so I care most not to wear out my welcome.

Thanks much for your appropriate reality check.

jeff k

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

Re: Identifying App folder Redux

Post by bogs » Sat Feb 01, 2020 5:08 pm

jmk_phd wrote:
Sat Feb 01, 2020 4:30 pm
Thanks much for your appropriate reality check.
Heh, only if it works, if it doesn't, I will deny all knowledge of the whole affair, and sweep that post under the rug :P
Image

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9580
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Identifying App folder Redux

Post by dunbarx » Sat Feb 01, 2020 5:09 pm

so I care most not to wear out my welcome
WRONG.

If I get lots of opportunities to reply here, I get to do less work at the office.

Craig

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7215
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Identifying App folder Redux

Post by jacque » Sat Feb 01, 2020 7:32 pm

I'm just awaiting word back from the student for whom the app broke in Catalina and from one who runs Windows. I'll update here what they report.
Just to confirm, you'd use my suggestion only for OS X and continue to branch for Windows OS.

And please don't worry about asking questions already posted elsewhere. No one can keep up with the flow of info here. Just do an initial search first but if you can't find answers we'll give them again.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

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

Re: Identifying App folder Redux

Post by bogs » Sat Feb 01, 2020 9:24 pm

dunbarx wrote:
Sat Feb 01, 2020 5:09 pm
so I care most not to wear out my welcome
WRONG.
If I get lots of opportunities to reply here, I get to do less work at the office.
Craig
Yah, same here, really it was just my warped sense of humor, I'd not want to make you feel unwelcome by any stretch of the imagination :D
Image

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

Re: Identifying App folder Redux

Post by jmk_phd » Sun Feb 02, 2020 1:56 am

Well, I've just heard back from the student running macOS Catalina, who reports that the app still fails to recognize the resources contained in its subfolder when employing the recommended specialFolderPath("engine") function.

(To reiterate, the code employed formerly had worked fine up to and including macOS Mojave.)

Although there is an outside chance that the student -- probably a novice to macOS -- made some error, it's just as likely that the LC function specialFolderPath("engine") has broken in Catalina.

If so, this may be a bug that the LC folks need to address. I'll need to try compiling a standalone in LC Indy 9.5.1 before concluding that this has not already been corrected. I will update here what I Iearn.

jeff k

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7215
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Identifying App folder Redux

Post by jacque » Sun Feb 02, 2020 4:52 am

I doubt the app bundle has changed, so it could well be a permissions issue. Is the app installed in the Applications folder? Does it work if moved to the desktop?

What's the folder and file structure of the app?
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

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

Re: Identifying App folder Redux

Post by jmk_phd » Sun Feb 02, 2020 5:26 pm

The student having the problem with Catalina reports that she did indeed copy the folder containing the standalone and support files to her Applications folder. The structure of the folder containing the standalone is as follows:

/EAS-SABE
/EAS_Audiofiles -- (a folder containing 740 .wav files)
EAS-SABE -- (the standalone .exe or .app)
norms_combined.txt
norms_eas.txt
norms_sabe.txt

When the application is launched, it currently uses the suggested specialFoldersPath("engine") strategy to identify and save to a custom prop (cFolderPath) the path to the enclosing folder. (Previously it used the strategy illustrated in my initial post, which worked through Mojave.) But apparently in Catalina the constructed path to an audiofile -- e.g., cFolderPath & slash & "EAS_Audiofiles" & slash & "Itm1.wav" -- no longer works (because she cannot hear the audioclips). Moreover, she gets the error messages I use to report that the text files (e.g., cFolderPath & slash & "norms_combined.txt") could not be found and read into memory.

Might it be possible instead to set the defaultFolder manually on startup:

Code: Select all

set the itemDelimiter to slash
get the effective filename of this stack
set the defaultFolder to item 1 to -2 of it
then use a relative filepath (e.g., "EAS_Audiofiles" & slash & "Itm1.wav") to trigger an audioclip. And to use a relative pathname (e.g., "norms_combined.txt") to read that text into memory as a custom prop.

I understand that one alternative might've been to copy all support files into the standalone, but this would've bloated the app to 265+ MB -- which at my end requires 30 minutes to upload to a website via FTP. Although the audioclips are unlikely to change, the plain-text norms will require periodic updates as researchers collect additional data. Simply substituting updated norms to the program folder takes only a minute.

Obviously we won't know whether this defaultFolder strategy works until someone tries it in Catalina. I will report back.

jeff k

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7215
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Identifying App folder Redux

Post by jacque » Mon Feb 03, 2020 5:43 am

At this point it doesn't sound like a file path problem to me. You could get more information if you split your error checking into two parts. First check if the file exists and provide an error message if it doesn't. If the file exists, proceed to open it and if that fails, provide a different error message. Include the result and the system error in both responses so you can track down the actual cause.

I'm still thinking it sounds more like permissions, since I'd be very surprised if file and folder structures have changed.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply

Return to “Mac OS”