ask file command issue

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
raugert
Posts: 112
Joined: Thu May 26, 2016 9:30 pm
Location: Winnipeg, Canada

ask file command issue

Post by raugert » Thu Mar 05, 2020 11:20 pm

I use the following script to save a file. The file name displays correctly and the choice of file extensions appears correctly in the dropdown, but ...

1. It doesn't set the prompt "Please name the file:" anywhere in the window ( I expected it in the title bar like the answer file command)
2. All the files are grayed out.. I thought the selected file extension from the dropdown would hilite the corresponding files

Code: Select all

on mouseUp
ask file "Please name the file:" with ("documents/vmpb/" & field "lastfile") with type "TABLET File|vmpbx" or type "DESKTOP File|vmpb"
end mouseUp
I'm sure I'm missing something simple..

Mac OS High Sierra (10.13.6)
Livecode Indy 9.5.1

thanks,
Richard
Last edited by raugert on Fri Mar 06, 2020 6:16 am, edited 1 time in total.
Livecode Indy 9.6.11 (Stable)
MacOS Sonoma 14.2
Xcode 15.0.1 SDK 17.0

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

Re: ask file command issue

Post by dunbarx » Fri Mar 06, 2020 12:18 am

Hi.

Don't you need the word "filter" preceding the type? And are you allowed to specify two types?

Craig

raugert
Posts: 112
Joined: Thu May 26, 2016 9:30 pm
Location: Winnipeg, Canada

Re: ask file command issue

Post by raugert » Fri Mar 06, 2020 6:13 am

Thanks Craig,

I tried with the word 'filter' preceding type, but got the same result even when I specified only one type..

According to the dictionary, you can specify multiple file extensions|types.

This simple example doesn't show the prompt nor does it hilite the files with the extension type (csv)

Code: Select all

on mouseUp
   ask file "Save data as" with "/documents/" with type "CSV Files|csv"
end mouseUp
Livecode Indy 9.6.11 (Stable)
MacOS Sonoma 14.2
Xcode 15.0.1 SDK 17.0

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4003
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: ask file command issue

Post by bn » Fri Mar 06, 2020 10:18 am

Hi Richard,

when you use "ask file" all files are greyed out because the user can not choose from the files because you will be saving a file, only folders are not greyed out for the user to change the destination of the file.
You provide a title for the window with a prompt what to do and a name for the file to be saved.

Code: Select all

on mouseUp
   ask file "choose location to save to" with "myNewName.csv"
   if it is not empty then
      beep
      put it -- the user chose a location and optionally new name
      -- do your saving here with the name and path
   else
      put "the user canceled"
   end if
end mouseUp
It is the "answer file" where you can preselect the type of file the user can choose from

Kind regards
Bernd

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

Re: ask file command issue

Post by bogs » Fri Mar 06, 2020 11:09 am

Hi,
Not sure what
1. It doesn't set the prompt "Please name the file:" anywhere in the window ( I expected it in the title bar like the answer file command)
means. Here is a picture of what a correctly setup dialog should look like (on 'nix)
aPic_saveDialog.png
...
If you mean where it says 'Name', then you have to provide that in the script.

First thing that caught my attention was the way you constructed the line to save the file (the parts in bold) ~
ask file "Please name the file:" with ("documents/vmpb/" & field "lastfile") with type "TABLET File|vmpbx" or type "DESKTOP File|vmpb"
I am assuming that is the default path you want the save to go to, however it is an incorrectly formatted path far as I know.
ask file prompt [with defaultFilePath] [with type types [or type types ...]] [as sheet]
You repeated that format for the path in the second code listing, adding a slash in front... ~
ask file "Save data as" with "/documents/" with type "CSV Files|csv"
For a folder path, the starting slash is the root of the disc. I seriously doubt your documents folder is in the root folder.

I actually tested this on 'nix, and for whatever reason it went through to my root folder instead of returning an error, but I am not sure OSX would be so forgiving (will probably need to file a bug report later on this for 'nix :D ).

Anyway, the correct format for your statement should look something like ~

Code: Select all

ask file "Save data as" with "/home/user/Documents/vmpb/My_Filename.Extension" with type "CSV Files|csv"
That is a complete path from the root directory to a folder on 'nix, it could also (probably) be expressed as

Code: Select all

ask file "Save data as" with specialFolderPath("Documents") & "/vmpb/My_Filename.Extension") with type "CSV Files|csv"
to make it more universal, although that did not work here (probably bug report 2 :P ).

Also of note, here I had to capitalize the word "Documents" or it wound up in my home folder, so you probably have copies of anything you went all the way through in your home folder with "documents".

As well, if the last folder in your path doesn't exist, it will stop at the last existing folder. For instance, I don't have a folder "vmbp" on my system, so the last real folder was "Documents", and that is where the dialog went to.
Image

raugert
Posts: 112
Joined: Thu May 26, 2016 9:30 pm
Location: Winnipeg, Canada

Re: ask file command issue

Post by raugert » Mon Mar 09, 2020 2:05 am

Thanks Bernd and Bogs for the exhaustive report. The prompt on OSX usually appears in the title bar of the window as it does when using "answer File" command. The dictionary says the prompt should also work with "ask File" but it doesn't appear to. It's not a big deal for me, just thought it should work..

Bogs, You're right about the file path not being correct. It seemed to be working OK, but I realized that if the file path syntax is incorrect, it will default to the last path. Hence why it was always opening up at the correct location for me. I also included the "lastFile" name so that the user doesn't always have to look for it in the list. This way it automatically appears in the filename field. It works OK with the following code.

Code: Select all

on mouseUp
 ask file "Hello:" with specialFolderPath("Documents") & "/vmpb/" & field "lastFile" with type "CSV Files|csv" or type "TAB Files|tab"
end mouseUp
Thanks very much for your replies,

Richard
Livecode Indy 9.6.11 (Stable)
MacOS Sonoma 14.2
Xcode 15.0.1 SDK 17.0

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

Re: ask file command issue

Post by bogs » Mon Mar 09, 2020 9:28 am

raugert wrote:
Mon Mar 09, 2020 2:05 am
The prompt on OSX usually appears in the title bar of the window as it does when using "answer File" command. The dictionary says the prompt should also work with "ask File" but it doesn't appear to. It's not a big deal for me, just thought it should work..
For the ignorant among us (ME), could you please post a screen shot of what, exactly, you are not seeing?

1. take screen shot of dialog
2. draw an arrow pointing to the part you are talking about
3. type what should be there

I'd really appreciate it :D
Image

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

Re: ask file command issue

Post by FourthWorld » Mon Mar 09, 2020 5:02 pm

@raugert : I tested on Linux (Ubuntu) where it works as expected. I haven't yet tested on Mac. I was unable to find a bug report on this in the bug DB; you might consider submitting one: https://quality.livecode.com/

@bogs: The title bar (AKA "drag bar"), the very top of the window. You won't see the issue on Linux, as the prompt displays in the title bar as expected.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: ask file command issue

Post by [-hh] » Mon Mar 09, 2020 6:34 pm

@answer file:
This is a rather old problem with MacOS since 10.12 or so.
Originally both prompt and title were removed by the OS.
This was at least partially resolved by LC to show always the prompt (not in title).

Just try on newer MacOS:

Code: Select all

on mouseUp
  put "Hello there" into p1
  put "HELLO and GOODBYE" into p2
  answer file p1
  answer file p1 titled p2
  ask file p1
  ask file p1 titled p2
end mouseUp
to see the differences.
shiftLock happens

raugert
Posts: 112
Joined: Thu May 26, 2016 9:30 pm
Location: Winnipeg, Canada

Re: ask file command issue

Post by raugert » Mon Mar 09, 2020 7:17 pm

Hi Bogs,
Here's what it looks like on Mac when opening a file.

Image

Here's what I expected when saving a file.

Image

Here's what I get with [-hh] recommendation. It actually works OK for the prompt. Would never have figured out the "titled" parameter as it's not in the dictionary..

Image

Here's the code I used. I had to make sure the "titled" parameter was at the end otherwise I get an error..

Code: Select all

on mouseUp
   ask file "Hello:" with specialFolderPath("Documents") & "/vmpb/" & field "lastFile" with type "CSV Files|csv|csv" or type "TAB Files|tab|tab" titled "Save Data"
end mouseUp
However, the file type selection has no effect. The files are all greyed out, unlike in windows where only the selected file types are shown. Perhaps my syntax is wrong...

I appreciate all your comments. Great collaborative forum.

Richard
Last edited by raugert on Mon Mar 09, 2020 8:03 pm, edited 1 time in total.
Livecode Indy 9.6.11 (Stable)
MacOS Sonoma 14.2
Xcode 15.0.1 SDK 17.0

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: ask file command issue

Post by [-hh] » Mon Mar 09, 2020 8:00 pm

raugert wrote:The files are all greyed out
If have it not for all but *sometimes* for some of the files here on Mac (since my switch to MacOS 10.15).

But I can click/select the greyed out ones that are of correct type. Did you already try that?

Read also points (A) and (B) here (by Mark Waddingham):
http://lists.runrev.com/pipermail/use-l ... 57817.html
shiftLock happens

raugert
Posts: 112
Joined: Thu May 26, 2016 9:30 pm
Location: Winnipeg, Canada

Re: ask file command issue

Post by raugert » Mon Mar 09, 2020 8:13 pm

Yes, I did click on a grayed out file and it is recognized OK. I had a look at Mark's report. Apple did make some changes when they introduced the APFS file format in OSX 10.13. It might have something to do with that. I'll give it some time. Maybe it will work in the future.

thanks for you insight.
Richard
Livecode Indy 9.6.11 (Stable)
MacOS Sonoma 14.2
Xcode 15.0.1 SDK 17.0

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

Re: ask file command issue

Post by bogs » Mon Mar 09, 2020 11:04 pm

Thanks for the shots explaining it for the great un-washed masses (me) hee hee. Very helpful, and Richard is right, I don't see that here, even on OSX 10.6.x
Image

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”