Setting Path$ environmental variable

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Simon Knight
Posts: 845
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Setting Path$ environmental variable

Post by Simon Knight » Mon May 23, 2022 7:16 am

Hi,
The background to this question is that I am attempting to call exiftool from my Livecode stack. My commands work when used in the Apple Terminal but an error of "No such file or directory" is posted when the same command is called using the shell command in my Livecode application.

Using the which command from Terminal reports that Exiftool is stored in /usr/local/bin/

Code: Select all

which exiftool
/usr/local/bin/exiftool
and Terminal reports that this path is stored in the $PATH environmental variable

Code: Select all

echo "$PATH"
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin
However, when I used the same echo $Path command from within my Livecode App it did not include /usr/local/bin/ in the list. So it seems that Terminal adds the path for its own use. Note I said "used" as in past tense: this morning following a restart the echo command just returns an empty line when run from inside my Livecode App.

I have no idea what is happening and wonder if anyone can tell me how to access exiftool ?

A supplementary question is how can exiftool be bundled with a build?
best wishes
Skids

Simon Knight
Posts: 845
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: Setting Path$ environmental variable

Post by Simon Knight » Mon May 23, 2022 7:52 am

I have read the the text file etc/paths holds the $PATH values. Mine has the following

Code: Select all

/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
so I do not know why I keep seeing the No such file or folder warning.
best wishes
Skids

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1206
Joined: Thu Apr 11, 2013 11:27 am

Re: Setting Path$ environmental variable

Post by LCMark » Mon May 23, 2022 3:28 pm

@SimonKnight: The terminal environment is not quite the same as that which you get when you launch an app from Finder (i.e. dock, desktop, folder) by double-clicking. Environment variables are inherited from their parent processes - when you launch from Terminal, a LiveCode app will inherit the terminals environment variables (and thus path); when you launch from Finder, it will inherit the 'launch' processes environment variables.

In this case, the difference is that $PATH when launched from Finder will have the minimum (completely system controlled!) paths in it - whereas the Terminal init script (e.g. .bashrc or others) will have more.

This isn't a problem though - you can just use the full path to the executable you want to run when using shell. e.g.

Code: Select all

get shell("/usr/local/bin/exiftool ...")
In terms of packaging it with your app - you can include the executable it in the copy files pane of your app, and then the path to it will be:

Code: Select all

specialFolderPath("resources") & "/exiftool"
Note: Strictly speaking you can't put executables in app resource folders on macOS - however, there is some 'magic' the engine does to detect executables and put them in the right place, but still allow you to find them via specialFolderPath("resources").

Simon Knight
Posts: 845
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: Setting Path$ environmental variable

Post by Simon Knight » Mon May 23, 2022 3:40 pm

Hi Mark,

Thank you again for your reply. Unfortunately while the value in $PATH was the cause of an initial problem I have now discovered that I am unable to send any arguments. For example

Code: Select all

Shell("ls")
works fine but

Code: Select all

Shell("ls -l")
fails and reports

Code: Select all

zsh: command not found: ls -l
The command

Code: Select all

shell("echo $PATH")
returns

Code: Select all

zsh: no such file or directory: echo /usr/bin:/bin:/usr/sbin:/sbin
This seems to be both a valid result and an error. The upshot is that I am able to read the manual of exiftool because as you say

Code: Select all

Shell("/usr/local/bin/exiftool")
works but

Code: Select all

Shell("/usr/local/bin/exiftool -ver")
does not.

I have tried various forms of quotes around the arguments but nothing seems to work. I wonder if it is something in the settings of my copy of Livecode.
best wishes
Skids

Simon Knight
Posts: 845
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: Setting Path$ environmental variable

Post by Simon Knight » Mon May 23, 2022 4:26 pm

Mark replied the following in a report in the quality control site:
I can't reproduce your issues with 'shell' here - I suspect you might have some broken changes to some of the shell environment init scripts on your machine (have you tweaked anything in trying to get stuff to work?).
So my error: I was over using quotes and wrapping the whole command in quotes. Once I removed the quotes the commands work phew! Thanks again for explaining how the $PATH variable is set.

Simon
best wishes
Skids

Post Reply

Return to “Mac OS”