1

I'm using macOS Big Sur 11.5.2 and LibreOffice 7.2.0.4.

I want to associate a file extension (unknown to LibreOffice, eg ".myfileExtension") to a specific LibreOffice program.

In my particular case it's Calc. However, when I do the regular process to associate a file extension to a program using Open With in Finder, the only option is "LibreOffice" (not Calc in particular). If I set LibreOffice as the default program for that extension, LibreOffice opens the file with Writer.

I do not want to change the file extension to some extension already associated with Calc (like, guessing, ".tsv") because I have lots of this files and I am constantly generating new ones.

So, the question is: How do I get to associate a particular file extension with a particular LibreOffice program (Calc)?

4
  • Got it. I was hoping there might be a "trick" or something to be done. Maybe on LibreOffice side there is something to be done. I'll ask in LibreOffice forum and reply here if I get any answer. Sep 8 at 15:11
  • I am not sure of the complexity and practicality of what you are proposing. If it is more complicated than opening the file from calc (that's another way) or changing the files extensions then it is not really what I am looking for. Sep 8 at 15:47
  • Yes, I should probably have said that explicitly. I don't know what neither of those things is. In that case, I guess you can post that as an answer, although I'll certainly need more clarification/research. I'll try it and see how it goes. thanks! Sep 8 at 16:54
  • I've deleted my comments and added an alternate answer. Sep 8 at 18:59
0

Calc is not a separate standalone application as in what Excel is in Microsoft Office or like Numbers, which are fully functional standalone applications. As such, there is no default method thru Finder, Get Info and or Open With in macOS to associate a particular file extension with Calc, as it is just not a fully functional standalone application as with the aforementioned applications.

In your particular use case, the only practical reason to associate a give file extension with a given application is to be able to either double-click the file or press ⌘O in Finder and have it open in it. As that is not doable by the methods previously mentioned, an alternative is to select the file in Finder and either select a Service/Quick Action or press a keyboard shortcut and have the selected file open in the given application. If one is already in Finder then this certainly is much quicker and easier then going thru the application to open the file.

The following example AppleScript code, shown below, can be used in various ways, however, this will focus on creating an Automator Service/Quick Action and also assigning it a keyboard shortcut.

  1. In Automator, create a new Quick Action, as shown in the screen shot below the Notes: section, with the following settings: Workflow receives [no input] in [Finder]

  2. Add a Run AppleScript action, replacing the default code with the example AppleScript code, show below.

  3. Save the Quick Action as e.g.: Open in Calc

  4. Then assign it a keyboard shortcut in System Preferences > Keyboard > Shortcuts > Services, e.g.: ⌃⌥⌘O

  • Note: The first time using the Service/Quick Action I recommend not use the keyboard shortcut and after selecting the target file in Finder, then either from Finder > Services click e.g. Open in Calc, or it is available on the context menu, right-click the file and select it from Quick Actions or Services. After dealing with the Security & Privacy related prompts one can then use the keyboard shortcut.

Example AppleScript code:

set selectedItems to {}

tell application id "com.apple.finder"
    set selectedItems to selection as alias list
end tell

if selectedItems is {} then return

set posixPathOfLibreOffice to ¬
    the POSIX path of the (path to ¬
        application id "org.libreoffice.script")

set shellCMD to {¬
    "'", posixPathOfLibreOffice, ¬
    "/Contents/MacOS/soffice", "'", ¬
    space, "--calc", space} as string

repeat with thisItem in selectedItems
    set thisItem to the POSIX path of the contents of thisItem
    tell application id "org.libreoffice.script" to activate
    do shell script shellCMD & thisItem's quoted form
end repeat

Notes:

The example AppleScript code, shown above, was tested in Script Editor and as an Automator Service/Quick Action under macOS Catalina with Language & Region settings in System Preferences set to English (US) — Primary and worked for me without issue1.

  • 1 Assumes necessary and appropriate settings in System Preferences > Security & Privacy > Privacy have been set/addressed as needed.

The example AppleScript code can also be used as an AppleScript application and placed in the Toolbar of Finder, thus allowing it to be clicked after selecting the target file. I do this with some of the AppleScript scripts I use daily in Finder as it's the easiest method to automate what manually takes many more steps and time.

Automator Service/Quick Action:

enter image description here




Note: The example AppleScript code is just that and sans any included error handling does not contain any additional error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors. Additionally, the use of the delay command may be necessary between events where appropriate, e.g. delay 0.5, with the value of the delay set appropriately.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .