# Using OSX system-level shortcuts (specifically Dictionary look-up)? also, How to use a macro to run a script (to interact with another program)?

Hello,

Is there a way to use OSX system-level shortcuts (such as the Dictionary-look up feature) in Writer? I want to be able to highlight a word and have that word pasted into Mac's built-in dictionary application with a single keystroke.

In most applications, I can do this with a shortcut that is assigned globally within the OSX system, but for whatever reason, this doesn't work/ is disabled in LibreOffice (I assume so that it doesn't interfere with LibreOffice's own shortcuts).

I am a translator so being able to look up a word quickly this way would help me alot, and save me from having to copy the text, switch applications, navigate to the dictionary search bar, paste the text, and hit enter every time I need to look up a word.

an alternative solution would be to (bypass the system shortcut method and simply) copy and paste something from LO into another program using a macro, but I have no idea how I might program a macro to do this.

For info on the system level dictionary shortcut in OSX see the following Apple Support Website: https://support.apple.com/kb/PH11266?locale=en_US&viewlocale=id_ID

Thanks alot!

Tom

edit retag close merge delete

Sort by » oldest newest most voted

Hi lostinthesound

(menu):ToolsCustomiseKeyboard

You will first need to create a macro for the action that you want before what follows below. Part of that is easy ("highlight + copy the word into the Clipboard") but I'm hazy on the external features of the action ("paste into the Dictionary software search bar, search for it, copy the result") (I no longer use a Mac). Nevertheless, I'm going to assume that you have called the script "dictionaryIntegration". See bottom for the beginnings of such a script.

The following is drawn from the Writer help using 5.0.0.5:

## Step-by-step:

1. (menu):ToolsCustomiseKeyboard
2. In the Category list box, scroll down and open the "LibreOffice Macros" entry.
3. Click to get to where you have stored your script.
(this can easily be the most difficult part!)
(see below)
4. Open any scripting language entry to see the available modules + select the "dictionaryIntegration" module.
5. In the Function list box you will now see a list of all functions in that module. Select the "dictionaryIntegration" function.
6. Click the option button for LibreOffice or Writer
(this sets the scope of the action)
(the options will change according to which applications are currently open).
7. In the Shortcut Keys list box, select a key combination that you want to use and click Modify
(that key combo now appears within Keys next to your script)
8. Click on OK

## Errata:

• The 5.0.0.5 help says to look in the Category list box, open the LibreOffice Macros entry & look for:-

LibreOffice Macros : LibreOffice installation share directory
(available for all)
or
My Macros : LibreOffice user directory
(available only for the user)

I do not have any universal macros (that I know about) but also do not have the above sections. Instead, I have:-

user : (containing my user-macros)
share : (macros that I did not add)

• 5.0.0.5 has a Function list-box; the Help calls it a Commands list-box

## Notes:

• Scripts are often composed of multiple sub-routines. Top-level functions that make use of the same sub-routines are collected together into 'modules'.

## Workaround:

There is a simple workaround, as detailed at this mac forum post:-

1. Select word
2. Right-click selected word
3. (from the context menu) choose Synonyms
4. (from the sub-menu) choose Thesaurus…
5. (a pop-up dialog gives options to select):

## Macro Script:

I've written a script that you can use. However, there are lines at the bottom that need to be changed (at this moment it just calls a message-box with the text of the highlighted word(s)). Info on Shell().

dictionaryIntegration.odt (contains just the macros)

Sub dictionaryIntegration()
rem ----------------------------------------------------------------------
rem macro for MacOS use with Dictionary.app
''
rem define variables
dim doc            as object
dim cursor         as object
dim selection      as object
dim selections     as object
dim word_to_lookup as string

dim count%, cr$, lf$, ht$, i% cr = chr( 13 ) lf = chr( 10 ) ht = chr( 9 ) rem ---------------------------------------------------------------------- '' prog note: ThisComponent.getCurrentSelection() (or) '' ThisComponent.CurrentController.getTransferable() '' prog note: only one ... more ## Comments Thank you for your response. Of course, I know how to assign shortcuts for functions within LibreOffice, but what I want to do is access a system-level OSX function, i.e. another piece of software. I couldn't find a way to do that within the normal shortcut-assigning dialog. Perhaps it can be done with macros, but I don't really know how. ( 2015-09-01 03:52:45 +0200 )edit Thank you again for your response. Unfortunately it doesn't quite answer my question. I know how do assign macros as keyboard shortcuts, as you described in your post, but as you wrote " I'm hazy on the external features of the action... I'm going to assume that you have found a way to do it." I haven't, and this is the whole point of the question. Perhaps macros are the solution, but I do not know how or if it is possible to write a macro that accesses an external command. ( 2015-09-02 08:54:24 +0200 )edit Workaround added. I see from the forum post linked that neither MS-Office nor LO nor OO contain the necessary Mac system-integration code. Feature request? ( 2015-09-02 11:47:35 +0200 )edit Thanks again for your answer. So, this workaround simply looks up the word in the LO built-thesaurus? Because I'm doingt translation, a thesaurus won't help, but even if I were to download one of the available dictionaries it won't solve my problem, because I have several specialized dictionaries that I need to use the Mac Dictionary app as well as fact two other dictionary apps that I want be able to have access to. So, the "external application" part of the problem is the key. ( 2015-09-03 05:28:22 +0200 )edit One possible solution I thought of was somehow having LO run a small command-line like script that accesses those pieces of software? Is that possible? see http://apple.stackexchange.com/questions/90040/look-up-a-word-in-dictionary-app-in-terminal Googling, I found this as a possibility, but am not quite Macro-savvy enough to know if this will work: http://unix.stackexchange.com/questions/140537/run-terminal-commands-from-within-libreoffices-basic-programming ( 2015-09-03 05:29:15 +0200 )edit That last combo should do it (well found!). I've looked through my Macros (lots & lots) & I've never used 'Shell'. Typical. Your main issue is going to be the path/command syntax. Either locate the command smack in the middle of your$PATH, or (better) specify the full filename from root (plus, naturally, make sure that that command is accessible by everyone) (chmod 777 filename). I'll checkout Shell & advise further.

( 2015-09-03 13:53:10 +0200 )edit

I'm writing as much of the Macro for you that I can. I'll edit this as soon as is complete (only 6 hours so far).

Blooming heck! 8 hours. I'm badly out of practice. Nevertheless, it works fine (and almost first time, too). Now, if I can, I'll attach an ODT containing the full macro so that you can easily use it and/or add it to your system. I've never done that before, so it may take another 8 hours! (actually, pretty easy). No text, just the macro routines inside.

( 2015-09-03 20:08:56 +0200 )edit

Hey sorry it's taken a while to get back. Holy Cow, thanks a lot. 8 hours? Jeez if someone had asked me to do 8 hours of work for free I would have laughed in their face... thanks so much! I haven't tried it out yet, but I will tomorrow and report back. In the mean time, I will consider this as solved, since I'm pretty sure I can write a script to do the rest of the job.

( 2015-09-05 13:38:27 +0200 )edit

I've just tried on this mac.. <ctrl><command>-D _do_ pop up a dictionary search here, in writer and in calc

more

.... I probably should have mentioned this, but actually part of the problem may that I have reassigned the dictionary command to be <cmd>f2. Changing the binding back, yes it does work, but I have actually a second dictionary program I need to access in this way as well, and also, I need it to also show the app window not just the pop-up "tool-tip" display, so Alex's response does it for me. I should also mention that you can do the dictionary look-up with a three-finger tap.

( 2015-09-05 13:48:50 +0200 )edit
1

glad to see that you found a solution that works for your need. reading you topic I thought that the 'default-out-of-the-box' thing was broken, thanks for the clarification.

( 2015-09-06 19:38:27 +0200 )edit