Xcode keeps changing 'file type' into 'file kind'

In Project builder 10.2 I had no problem getting the file type using the ‘info for’ statement.
However in Xcode 10.3 I am having trouble getting the file type.

set infoRecord to (info for theFile)
set x to file type of infoRecord

In the scriptmaker this works OK and in Project Builder 10.2 I got the exact same result as below

tell current application
	info for alias "Mac OS 10.3.5:Applications:Safari.app:"
		{name:"Safari.app", creation date:date "vrijdag, 5 december 2003 21:00:00", modification date:date "vrijdag, 5 december 2003 21:00:00", icon position:{0, 0}, size:9.13239E+6, folder:true, alias:false, name extension:"app", extension hidden:true, visible:true, package folder:true, file type:"APPL", file creator:"sfri", displayed name:"Safari", kind:"Programma", short version:"1.2.4", long version:"1.2.4, Copyright 2004 Apple Computer, Inc.", bundle identifier:"com.apple.Safari"}
end tell

In Xcode 10.3 the same statements results is this:

{«class hidx»:true, «class kind»:"Application", «class assv»:"1.2.4", name:"Safari.app", «class asct»:"sfri", «class ispk»:true, «class asdr»:true, «class aslv»:"1.2.4, Copyright 2004 Apple Computer, Inc.", file type:"APPL", «class bnid»:"com.apple.Safari", «class asmo»:date "vrijdag, 5 december 2003 21:00:00", size:9.13239E+6, «class asip»:{0, 0}, alias:false, «class dnam»:"Safari", «class nmxt»:"app", «class ascd»:date "vrijdag, 5 december 2003 21:00:00", visible:true}

There is a ‘file type’ in this record but Xcode does not allow me to request for it because it keeps changing the statement ‘file type’ into ‘file kind’

 on awake from nib theObject
	-- Using the Finder works, but has an unacceptable delay	
	tell application "Finder"
		set infoRecord to (info for theFile)
		set x to file type of infoRecord
	end tell
	
	-- This results in an error
	set infoRecord to (info for theFile)
	set x to file kind of infoRecord 
end awake from nib

So my question is: How do I get the file type without asking the Finder in Xcode 10.3?
I don’t want this record, I need to have it the way it was in 10.2. Can this be done in 10.3 somehow?

Thanks in advance,

John

This is a recognized problem and has been covered here a few times. Although probably not what you want to hear, answers and workarounds can be found in a number of posts found when searching for “file kind type” in this forum…
Commands different between xcode and script editor
file type changed to file kind in applescript studio
j

Thank you, I found the solution there. (set theFileType to item 12 of ((info for (alias theItem)) as list))

There is however still a 10.2/10.3 incompatibility.
My projects must run on both 10.2 and 10.3 but the source code is simply not compatible. I assume that the ‘kind’ is not yet available in 10.2. So I have to think of a way that one version can cover both OS’s.
That means that I have to know the version of the OS.
In the Finder dictionary I read the property “product version” which should tell the OS version but with me this returns an empty string.
Because I don’t know any other way I decided to try this:

set infoRecord to (info for theItem)
try
		set theKind to kind of infoRecord
		set OSversion to "10.3"
on error
		set OSversion to "10.2"
end try

It works, but is clumsy.
Is there a better and and safer way?
Am I doing something wrong with getting the OS version from the Finder?

Thanks in advance.

John

I did some searching and found a good bit of code on this page at apple’s list archive and modified it to suit your needs. The following code will query the SystemVersion.plist file, which stores the ‘official’ version information for the system. Check the file to see if there’s a different key you’d like to search for, as there are two different ones that look the same but may change with future releases of osx. A good point was made on the page above about the defaults command not working on systems without the BSD subsystem installed, so you may want to adding some error handling and use a second method to get the string if it’s not installed.

set plist to ((POSIX path of (path to library folder from system domain)) & "/CoreServices/SystemVersion") -- as string) --as alias
set search_key to "ProductUserVisibleVersion"
set res to (do shell script "defaults read '" & plist & "' " & search_key)
--> returns "10.3.7" on my box

If this scares you or won’t work, here are some other methods I came up with…

set SVPlist to (((path to library folder from system domain as string) & "CoreServices:SystemVersion.plist") as string) as alias
set tmpData to (read SVPlist) as string

set AppleScript's text item delimiters to {"ProductUserVisibleVersion</key>
	<string>"}
set tmpData to (text item 2 of tmpData) as string
set AppleScript's text item delimiters to {"</string>"}
set tmpData to (text item 1 of tmpData) as string
set AppleScript's text item delimiters to {""}

return tmpData --> Returns "10.3.7"

This next one I assume will let you know 10.2/10.3, but is unreliable for getting the latest OS version installed. It reads the version from the Finder, not the system. On my machine, the system is at 10.3.7, but the actual finder application is really the 10.3.2 version, so this method returns .2 rather than the system version which is .7. It’s strength is in it’s simplicity, but all my machines are 10.3 so I can’t test this out for you.

set OSPath to (((path to library folder from system domain as string) & "CoreServices:Finder.app:") as string) as alias
set OSVersion to short version of (info for OSPath) as string

Hope one of them does the job for you…
j

This is, I believe, the preferred way to get the OS version:

Jon


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]