Checking if XLS or DOC is able to open in Mac

Hi, I know when i want to check if doc or xls is able to open on Windows, i check the registry "“HKEY_CLASSES_ROOT\.???\OpenWithList”. What do i need to do for using on the Mac OSX??

https://developer.apple.com/library/mac/documentation/Carbon/Conceptual/LaunchServicesConcepts/LSCTasks/LSCTasks.html#//apple_ref/doc/uid/TP30000999-CH203-SW4

This would require the use of declares. I’m unaware of CLI tools to achieve the same goal but there might be.

Keep in mind, though, that for historical reasons in OSX there are several ways to open a file:

  1. OSType (e.g. “TEXT”)
  2. File name extension (e.g. “.txt”)
  3. A UTI (e.g. “public.text”)

Then there’s the MIME types. For example:

JavaScript:
“text/javascript”

CSS:
“text/css”

HTML:
“text/html”

wonder if MBS has anything for checking this… or maybe in macoslibs??

  Dim f As FolderItem
  f = GetOpenFolderItem("")
  f.Launch
  if f.LastErrorCode<>0 then
    msgbox "Failed to launch"
  end if

[quote=26988:@Dave S] Dim f As FolderItem f = GetOpenFolderItem("") f.Launch if f.LastErrorCode<>0 then msgbox "Failed to launch" end if [/quote]

Oh. I LIKE this. So obvious :smiley:

dim f as FolderItem
f = LaunchServicesFindApplicationForInfoMBS("","com.microsoft.Word","")
if f.Exists then cmdExportWord.Enabled=true  ELSE cmdExportWord.Enabled=false 
f = LaunchServicesFindApplicationForInfoMBS("","com.microsoft.Excel","")
if f.Exists then cmdExportExcel.Enabled=true  ELSE cmdExportExcel.Enabled=false

You can ASK launch services which apps can open a document (there may be several)
Im fairly sure that MacOSLib has code for querying this

you mean give them the doc or xls extension and ask them what is available.

So even if the user doesn’t has MS Word or MS Excel but something that can open, it still can open the files.

Dave, where is the extension doc or xls in your code??

there isn’t… doesn’t need to be…
by default it does what Norman implied… if it can find a valid app to launch with it will… if not if fails…

So DOC will openwith Word or any other approrpiate word processor, XLS if you have EXCEL installed etc.

so it is not limited to DOC or XLS… if will work on what ever folderitem you give it…

i see what you mean now… but what i need is disabled the button if not available.

does it have to meet AppStore rules (ie. Sandbox etc)
if NOT… look at this shell command I found

/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -dump | grep -n7 ‘your search string’

interesting… so i didn’t get anything back after the shell, it mean can’t find the program. So i can replace ‘your search string’ with ‘Microsoft Word’ or ‘Microsoft Excel’

I’d leave the | and all after it off… and see what it DOES return…
I have Word and Excel on my iMac so I’ll see what it actually does find for those

com.microsoft.word.doc, com.microsoft.word.dot, com.microsoft.word.stationery
com.microsoft.excel.xls, com.microsoft.excel.xlt

[quote=27014:@Richard Duke]you mean give them the doc or xls extension and ask them what is available.

So even if the user doesn’t has MS Word or MS Excel but something that can open, it still can open the files.[/quote]

No - you can literally have a file and get LaunchServices to say “here’s the preferred application on this machine to open it”
Or if you just do f.launch that too will use whatever the user has that can offer to open it if they have anything

So if a user has Apple’s Numbers app and not Excel then when you do f.launch on an Excel file Numbers will probably open the file.

We have the LaunchServicesApplicationForItemMBS function for this.
Should find Excel for an excel file if that’s the current setting.

christian, what do i need to pass over as parameter for LaunchServicesApplicationForItemMBS?? I am doing it like this right now.

dim f as FolderItem
f = LaunchServicesFindApplicationForInfoMBS("","com.microsoft.Word","")
if f.Exists then cmdExportWord.Enabled=true ELSE cmdExportWord.Enabled=false 
f = LaunchServicesFindApplicationForInfoMBS("","com.microsoft.Excel","")
if f.Exists then cmdExportExcel.Enabled=true ELSE cmdExportExcel.Enabled=false

[quote=27083:@Richard Duke]christian, what do i need to pass over as parameter for LaunchServicesApplicationForItemMBS?? I am doing it like this right now.

dim f as FolderItem f = LaunchServicesFindApplicationForInfoMBS("","com.microsoft.Word","") if f.Exists then cmdExportWord.Enabled=true ELSE cmdExportWord.Enabled=false f = LaunchServicesFindApplicationForInfoMBS("","com.microsoft.Excel","") if f.Exists then cmdExportExcel.Enabled=true ELSE cmdExportExcel.Enabled=false [/quote]
Why bother ?
Really … if you have an excel file use f.Launch & the users preferred app will open it. (They could actually designate to open all Excel files with Numbers for instance)

i don’t want to open the xls or doc and discover i can’t. i want to disable the button before i can click on it.

So again… as long as Sandboxing is not a requiriement… what is wrong with the shell command I provided… I even gave you what it needs to search for