Sunday, May 9, 2021

#1 2021-04-30 01:17:45 pm

joecab
Member
From:: Boston MA
Registered: 2006-01-23
Posts: 37

choosing a file by extension rather than type

I know you can make a system prompt for opening a certain type of file, like:

   set directory to POSIX path of ( choose file of type ("public.image") with prompt ...

But instead of filtering for files by type, can I use file extensions instead? It sounds pretty straightforward but I haven't found the answer in my poking around the AS dictionary.

Last edited by joecab (2021-04-30 01:18:20 pm)

Offline

 

#2 2021-04-30 04:23:02 pm

Marc Anthony
Member
From:: Dallas, TX
Registered: 2006-04-27
Posts: 1017

Re: choosing a file by extension rather than type

Hi. Finder can filter by name:

Applescript:

tell application "Finder" to (my (choose folder)'s files whose its name ends with ".pdf" or its name ends with ".jpg") as alias list

Offline

 

#3 2021-05-01 03:15:35 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 5378

Re: choosing a file by extension rather than type

choose file both accepts and heeds extensions on my Mojave system:

Applescript:

set directory to POSIX path of (choose file of type {"pdf", "scpt", "txt", "png"} with prompt "Choose one of the chooseable files:")


NG

Offline

 

#4 2021-05-01 08:01:27 am

Marc Anthony
Member
From:: Dallas, TX
Registered: 2006-04-27
Posts: 1017

Re: choosing a file by extension rather than type

Hmm, so it does. I attempted to use the period, which breaks the functionality and may be the same mistake the OP made.

Offline

 

#5 2021-05-02 11:00:01 am

joecab
Member
From:: Boston MA
Registered: 2006-01-23
Posts: 37

Re: choosing a file by extension rather than type

Great solutions all, but let me complicate things further: this script is to prompt the user to open a file with a custom extension. Underneath, the file type is supposed to really be TEXT, but for some reason not all of them are recognized as such when I use "of type {"TEXT"}".

That's why I was hoping the bypass the filetype completely and only look at the custom file extension since that's unique to any doc created by this app.

(To clarify: older versions of the app stuck to making these .abcd files of type TEXT, but the newer version didn't. That's why I was thinking to just look at that .abcd file extension which is always present.)

Last edited by joecab (2021-05-02 11:06:46 am)

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)