Page 1 of 1

How to handle file stacks with an integer as name?

Posted: Thu Nov 24, 2016 3:08 pm
by Mag
I noticed that If i assign to a new stack a number, for example 2, then I have problems to handle it because LC thinks that I'm talking of the stack 2, not the stack with the short name "2".

Code: Select all

create invisible  stack "2"
If is it a limit of LC, is there a way to avoid this? I can't choice the name because is the user that choice it.

PS
This happens in my code and could be a problem I create with some logical error in some statement.

Re: create invisible stack "2"

Posted: Thu Nov 24, 2016 4:53 pm
by dunbarx
Mag.

It is NEVER a good idea to use an integer to name anything, control, stack, whatever, because you will inevitably create a conflict between LC's native properties, as you discovered, and likely already knew.

Can't you direct the user to use something that is not an integer?

Or perhaps name your stack "XYZ 2", and then write a code snippet that asks something like (pseudo)

Code: Select all

ask "which stack?"
--  user enters "2"
go stack "XYZ" && it
In this way LC is happy, the user is happy, and happy Thanksgiving.

Craig

Re: create invisible stack "2"

Posted: Thu Nov 24, 2016 4:59 pm
by Mag
Thank you Craig.

The name entered by the user is used for naming a file saved on disk, so I haven't the possibility to use a different name from the one assigned to the user. What's more the user can change the name of the stack in the Finder.

Having not control over the name of the stack file, is there a way to use the ID to refer to the stack to save it on disk and set/read its properties?

Re: Using stacks with an integer as name

Posted: Thu Nov 24, 2016 6:27 pm
by jmburnod
Hi Mag,
What's more the user can change the name of the stack in the Finder
And they can also move the file...
I wonder if you can use one substack for each user.
Jean-Marc

Re: Using stacks with an integer as name

Posted: Thu Nov 24, 2016 6:43 pm
by dunbarx
Jean-Marc's idea of using substacks has the advantage that they cannot be accessed apart from the mainStack, so the re-name thing might go away.

But the mainStack itself can be moved and renamed. There is no way for LC to know about this sort of shenanigans. Either get better users, or force them to reset the pathname if it all of a sudden does not exist in the expected location. This can be easily tested, and if it has been moved, it serves them right to have to find it again. If it has been renamed, you can charge for customer support.

Craig

Re: Using stacks with an integer as name

Posted: Thu Nov 24, 2016 6:49 pm
by Mag
Thank you for the info. Anyway I'm using stack files ad app documents (they only store properties and I open them invisible when user double click them on the Finder only for read and write properties), so users have to have them available on the disk as icon to open them, share, delete and so on...

Re: Using stacks with an integer as name

Posted: Thu Nov 24, 2016 7:16 pm
by jmburnod
I understand I did the inverse for an app multiusers.
The app open a list of users with edit tools (new, erase, rename, choose a picture etc..).
Each user have a folder in documents folder with .txt and .png files.
When the user choose his name the content of his folder is available for app.
What is the best way ? I don't know :roll:

Re: How to handle file stacks with an integer as name?

Posted: Fri Nov 25, 2016 8:09 pm
by jacque
The script can check the name the user enters and if it is a single integer, put up a second dialog telling them that the name must include at least one alphabetic character.

A second method would be for the script to add its own identifier. So if the user enters 2, the script would name the stack "file 2". If you want, you can also set the stack label to "2" so the user doesn't know about it.

Re: How to handle file stacks with an integer as name?

Posted: Fri Nov 25, 2016 8:20 pm
by Mag
jacque wrote:The script can check the name the user enters and if it is a single integer, put up a second dialog telling them that the name must include at least one alphabetic character.

A second method would be for the script to add its own identifier. So if the user enters 2, the script would name the stack "file 2". If you want, you can also set the stack label to "2" so the user doesn't know about it.
Thank you Jacque, this solves the problem when the file is saved on disk, but remains a problem: I have not control over what the user does in Finder with its stack files... :cry:

Re: How to handle file stacks with an integer as name?

Posted: Fri Nov 25, 2016 8:25 pm
by jacque
You can't control the location of the file. The script should check the existence of the file before trying to open it and if it does not exist, put up an open file dialog asking the user to locate it.

If they see that enough times maybe they will leave it where you originally put it. :-)

Edit : My experience has been that if you store user files in Preferences or Application Support, users will rarely move them.

Re: How to handle file stacks with an integer as name?

Posted: Fri Nov 25, 2016 8:35 pm
by Mag
My problem is with documents that the user creates (which can be open it with a double click on the Finder)... :oops:

Re: How to handle file stacks with an integer as name?

Posted: Fri Nov 25, 2016 9:20 pm
by FourthWorld
Mag wrote:My problem is with documents that the user creates (which can be open it with a double click on the Finder)... :oops:
The file name of a stack file need not be the same as the names of the mainstack and any substacks within it.

If you need to ensure unique names for stack objects within a stack file you might consider the UUID function.

Re: How to handle file stacks with an integer as name?

Posted: Fri Nov 25, 2016 10:16 pm
by Mag
FourthWorld wrote:
Mag wrote:My problem is with documents that the user creates (which can be open it with a double click on the Finder)... :oops:
The file name of a stack file need not be the same as the names of the mainstack and any substacks within it.

If you need to ensure unique names for stack objects within a stack file you might consider the UUID function.
Thank you. Actually the stack names ar unique (I check and don't open two stacks files with the same name). The problem appears when I use a number as stack name. Can I refer to a stack with its fulmpath on disk to read its propertyes?