Sunday, April 21, 2019

#1 2019-02-14 01:34:50 pm

GG
Member
Registered: 2019-01-14
Posts: 98

Can one determine the extensions that invoke a particular app?

I am able to find out what the default app is for a particular file extension.

Is there a way to look at a particular app and determine the list of file extensions that invoke it as the default app (i.e. the reverse)?

I suspect that there likely isn't a method for doing this quickly, but I won't know if I don't ask.

Offline

 

#2 2019-02-14 02:02:41 pm

alldritt
Site Admin
From:: Victoria, B.C. Canada
Registered: 2002-12-12
Posts: 37
Website

Re: Can one determine the extensions that invoke a particular app?

You could read the application's Info.plist file and then look at the CFBundleDocumentTypes key values to see the types of documents the app will open.


Mark Alldritt - Late Night Software Ltd.
support@latenightsw.com | mark@macscripter.net

Offline

 

#3 2019-02-14 05:10:34 pm

GG
Member
Registered: 2019-01-14
Posts: 98

Re: Can one determine the extensions that invoke a particular app?

Thank you for the suggestion. I wasn't aware that this was always possible. Will have a go at that.

Offline

 

#4 2019-02-14 05:33:21 pm

GG
Member
Registered: 2019-01-14
Posts: 98

Re: Can one determine the extensions that invoke a particular app?

I had a look at the Info.plist is the bundle itself. Is this the instance you meant?

For something like my app, there is a section "Information Property List">"Document Types (array)" that appears to be a list of keyed lists. "Item 0" (dictionary)>"CFBundleTypeExtensions (array)">"Item0" (String) is currently showing "*".

I remember in Script debugger you can set the types of files the app handles. Is this item 0 that is currently "*" set by compiling the script with that compiler blank filled in?

If so, I need to fill it in first and then I can search for it in the dictionary. ... I think. :>)

Offline

 

#5 2019-02-14 10:29:38 pm

alldritt
Site Admin
From:: Victoria, B.C. Canada
Registered: 2002-12-12
Posts: 37
Website

Re: Can one determine the extensions that invoke a particular app?

The "*" file type is a wildcard that matches any type of file.  You can change it to something like "jpeg" to match files with that filename extension.  The array allows there to my multiple file types: "jpg", "jpeg", "png", etc.


Mark Alldritt - Late Night Software Ltd.
support@latenightsw.com | mark@macscripter.net

Offline

 

#6 2019-02-15 02:45:12 pm

GG
Member
Registered: 2019-01-14
Posts: 98

Re: Can one determine the extensions that invoke a particular app?

Mark;

I'm using the following code to allow access to the user defaults.

Applescript:

   if my id = missing value then error "This code works only in an applet or script bundle."
   if current application's id = my id then -- must be running as applet
       set theDefaults to current application's NSUserDefaults's standardUserDefaults()
   else -- being run by editor or other host app
       set myPath to POSIX path of (path to me)
       set theData to current application's NSData's dataWithContentsOfFile:(myPath & "Contents/Info.plist")
       set infoDict to current application's NSPropertyListSerialization's propertyListWithData:theData options:0 format:(missing value) |error|:(missing value)
       set myID to infoDict's objectForKey:"CFBundleIdentifier"
       set theDefaults to current application's NSUserDefaults's alloc()'s initWithSuiteName:myID
   end if
   
   -- This reads a value for a key and returns it via the method objectForKey.
   set theValidExtensions to theDefaults's objectForKey:"CFBundleDocumentTypes"

However; this appears to work only if the value for a key is changed. I believe that Shane's book noted that a value doesn't get loaded into the internal database unless it is changed from the plist file defaults.

As such; I assume that I need to take the same approach as if I were running in an editor and initially read the plist file directly. That's fine, if all I need to do is find out a value. If I need to write it (and possibly re-read it), I think I need to register it (which loads it into the internal database). That way; if I change it in the internal database, it will be re-written to the plist file and persist between runs.

Am I making any sense here?

Offline

 

#7 2019-02-15 04:46:00 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5626

Re: Can one determine the extensions that invoke a particular app?

Info.plist entries aren't meant to be modified. It's fine for a script app, but otherwise you risk breaking the app's code-signing.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)