What is the fileformat for .QIF files in Applescript?

We use the code on Ron De Bruin’s website www.rondebruin.nl/mac/mac015.htm to select files using VBA on Excel for Mac 2016.
This code incorporates some applescript according to which ( for example )

FileFormat = “{”“public.plain-text”“}”

gets .TXT files shown on the dialogue box for choosing a file. This works fine.
How do we alter this to choose .QIF files which are used for financial data?
Thanks

Can you post more of the Applescript so we can see what it is doing?

Thanks for your interest.

This is an extract from Ron de Bruins code on the web site mentioned above. This particular extract puts a dialogue box on the screen and it returns the name of a chosen excel .xlsx file in the string MyFiles.

Sub Select_File_Or_Files_Mac() ’ For Mac Excel 2016
Dim MyFiles As String
Dim FileFormat as string

'In this example you can only select xlsx files

FileFormat = “{”“org.openxmlformats.spreadsheetml.sheet”“}”

MyScript = _
“set theFile to (choose file of type” & _
" " & FileFormat & " " & _
“with prompt ““Please select a file”” default location alias “”” & _
MyPath & “”" without multiple selections allowed) as string" & vbNewLine & _
“return theFile”

MyFiles = MacScript(MyScript)

end sub

My objective is to get this code to get me the name of a .QIF file instead of an .xlsx file.
I have tried replacing with FileFormat = “{”“public.qif”“}” and other things without success.

There is a list of 15 possible values of FileFormat on Ron’s web site but the value for financial .QIF files is not included.

Try that to find the info you need


set SomeFile to POSIX file "/file.qif"
set ItemInfo to (info for SomeFile)

Untested, I’m on mobile. Maybe you need to wrap within a tell application Finder block.

Hi,

“public.plain-text” is the uniform type identifier (UTI), you can retrieve it easily with AppleScriptObjC

use framework "Foundation"

set theFile to choose file

set fileURL to current application's NSURL's fileURLWithPath:(POSIX path of theFile)
set uriResource to fileURL's getResourceValue:(reference) forKey:(current application's NSURLTypeIdentifierKey) |error|:(missing value)
display dialog (item 2 of result as text)

Hello Stefan

You forgot one instruction required by the use of choose file :wink:

use framework "Foundation"
use scripting additions # was missing

set theFile to choose file

set fileURL to current application's |NSURL|'s fileURLWithPath:(POSIX path of theFile)
set uriResource to fileURL's getResourceValue:(reference) forKey:(current application's NSURLTypeIdentifierKey) |error|:(missing value)
display dialog (item 2 of result as text)

Yvan KOENIG running Sierra 10.12 in French (VALLAURIS, France) dimanche 16 octobre 2016 18:24:34

Thanks for so many suggestions.
We are OK at VBA here but at the Hello World stage for Apple script. But these leads looks promising. If and when I get a result I’ll post it.
regards.

Success.

The file type identifier for financial .QIF files on the Mac is “com.apple.traditional-mac-plain-text”.
This can be use in Ron de Bruins VBA code as: FileFormat = “{”“com.apple.traditional-mac-plain-text”“}”

I tried several of your suggestions to get this identifier. The one that I got to work was from StevenH which I used as follows
I had a sample .qif file in the downloads directory and ran the following:



tell application "Finder"
set somefile  to POSIX file "/users/myfolder/downloads/test.qif"
set siteminfo to (info for somefile)
end tell


The system then gave me 8 lines of information about .qif files including what I need i.e. the type identifier.

Thanks StevenH and every one.

In addition to complete this post:

Not every application supports the newer UTI. Some application still uses the old OSType codes (type and creator code). The latest version of InDesign CC still registers document type by Type code rather than the newer UTI. So to give the application and it’s documents a UTI it is a randomly generated string which can change between updates and is different between machines. For better stability it can be better not to use the UTI but the type code which is a four byte code. The four byte code is given by the info for command and can be used as well in a choose file of type dialog.

to select only indesign documents you can use (be aware that the identifier is byte code so it’s case sensitive).

-- for portability with all indesign versions:
-- respectively: Indesign standard, CS, CS2, CS3, CS4, CS5, CS 5.5, CS6, CC, CC 2014, CC 2015
choose file of type {"InDd", "IDd3", "IDd4", "IDd5", "IDd6", "IDd7", "IDd2", "IDd8", "IDd9", "IDdX", "IDdB"}

It’s not a clean code.
1 – info for is deprecated
2 – info for belongs to the OSAX standard Additions so it’s bad practice to call it in a tell application block.

If you really want to use info for, the clean way is :

set somefile  to  "/users/myfolder/downloads/test.qif"
set itsID to type identifier of (info for someFile)

If you want to use a really clean code, use :

set somefile  to  "/users/myfolder/downloads/test.qif"
tell application "System Events"
	set itsID to type identifier of disk item someFile
end tell

Here, as I don’t have an application creating/using qif files, there is no UTI available, I got : “dyn.ah62d4rv4ge81c4pg”

Yvan KOENIG running Sierra 10.12.0 in French (VALLAURIS, France) lundi 17 octobre 2016 14:40:21