Is there a way, given a filetype of determining the default handler for the file and launching the application with the file.
For instance if I had a folder item which had test.xls as the file, can I determine if the user has an xls file handler and attempt to launch it with the file I have in the folder item.
[code]declare function NSClassFromString lib “Foundation” (clsName as cfstringref) as ptr
declare function sharedWorkspace lib “Foundation” selector “sharedWorkspace” (clsRef as ptr) as ptr
declare function openFile lib “Foundation” selector “openFile:” (obj_id as ptr, file as cfstringref) as boolean
// f is the folder item to open
if openFile(sharedWorkspace(NSClassFromString(“NSWorkspace”)),f.path) then
//successfully opened the file
else
//failed to open the file
end if[/code]
I thought that he wanted to get the name of the app which opens the file and then use that information to launch the file. Since you don’t need to know the application to attempt to open the file I ignored that part. If he wants the app name then I think he can do (using Sam’s function, and including the same declares from above):
declare function URLForApplicationToOpenURL lib "Foundation" selector "URLForApplicationToOpenURL:" (obj_id as ptr, url as ptr) as ptr
declare function URLWithString lib "Foundation" selector "URLWithString:" (clsRef as ptr, str as cfstringref) as ptr
declare function lastPathComponent lib "Foundation" selector "lastPathComponent" (obj_id as ptr) as cfstringref
dim appURL as ptr = URLForApplicationToOpenURL(sharedWorkspace(NSClassFromString("NSWorkspace")),URLWithString(NSClassFromString("NSURL"), f.Path))
dim appName as Text = lastPathComponent(appURL)
Dim f As FolderItem = GetOpenFolderItem("")
declare function NSClassFromString lib "Foundation" (clsName as cfstringref) as ptr
declare function sharedWorkspace lib "Foundation" selector "sharedWorkspace" (clsRef as ptr) as ptr
declare function openFile lib "Foundation" selector "openFile:" (obj_id as ptr, file as cfstringref) as boolean
declare function URLForApplicationToOpenURL lib "Foundation" selector "URLForApplicationToOpenURL:" (obj_id as ptr, url as ptr) as ptr
declare function URLWithString lib "Foundation" selector "URLWithString:" (clsRef as ptr, str as cfstringref) as ptr
declare function lastPathComponent lib "Foundation" selector "lastPathComponent" (obj_id as ptr) as cfstringref
dim appURL as ptr = URLForApplicationToOpenURL _
(sharedWorkspace(NSClassFromString("NSWorkspace")),URLWithString(NSClassFromString("NSURL"), f.UrlPath))
dim appName as String = lastPathComponent(appURL)
OpenFileLabel.Text = appName