Console app and default variables

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
gragon
Posts: 14
Joined: Thu Nov 30, 2006 3:54 am

Console app and default variables

Post by gragon » Thu Oct 08, 2009 6:02 am

I have been searching the forums and the runrev dictionary, but I am unable to find an answer. The last thing I want to do is ask something that is easy to find the answer to.

I come from a Java, C/C++, Python, and PHP background.

1. Is there a way to get the username, and user default directory (not the directory the app was launched from), without having to prompt the user for the information?

2. Is there an "ask" method equivalent for console applications? I would like to prompt the user for input from the command line.

Many thanks.

Paul D
Posts: 116
Joined: Mon May 21, 2007 6:58 pm

Post by Paul D » Thu Oct 08, 2009 2:35 pm

The last thing I want to do is ask something that is easy to find the answer to.
Balderdash! The community here is great and will help anyone with the simplest of questions, I know, I ask a lot of them.

If Im understanding you correctly you want to read the OS variables that store the username and default directory? You can use $ for that. In windows, $USERNAME returns the username of the computer for example. Does that help?

Im not sure about a command line ask.

gragon
Posts: 14
Joined: Thu Nov 30, 2006 3:54 am

Post by gragon » Thu Oct 08, 2009 4:02 pm

You can use $ for that.
Thank you, I was not aware of that. Admittedly, I was hoping for something similar to other high level languages like the following Java example.
System.getProperty("user.name");
System.getProperty("user.dir");

However after testing this a bit, I have some concerns. What concerns me about using environment variables is that they can be changed at execution by the user.

For example:
export USER=arnold

I can see this raising some security flags with some types of applications.
Last edited by gragon on Thu Oct 08, 2009 4:24 pm, edited 2 times in total.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Post by FourthWorld » Thu Oct 08, 2009 4:06 pm

Paul's tip is very helpful. On OS X the user name is in $user, which I believe may also be the same on Ubuntu but I haven't checked.

To get a list of all such global variables run this in the Message Box:

put the globalnames

That will list all global variable names currently available. Those preceded with "$" are system variables.

For example, $HOME on OS X is the path to the user's home directory. Lots of good stuff to be found there.

Paul's comment about asking questions was also spot-on: I ask a lot of questions for which the answer turns out to seem obvious, but if it was so obvious why was it a question? I think for every "dumb" question posted there are a hundred other people who want the answer but haven't asked it. So please ask away; it'll help a lot more folks than just you.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply