Hi!
My first post here, and thank you for this wonderful resource of Applescript knowledge
Now to my problem: I’m a translator, and I wrote a script/Automator workflow (with the help of many posts in this forum) which acts as a kind of glossary/dictionary:
I have a simple tab-delimited TXT file with glossary terms, such as:
carAuto
(for e.g. English to German)
So, when I select a word (or a longer string) in any app, I press a keyboard shortcut, which calls my script, which does the following:
- checks if the selected string exists in the glossary file
- if it does, it returns the translation (second column) (pastes it over the original selection)
- if the selected string is not in the glossary file, a dialog opens asking you to enter a new translation (which is then added to glossary file, and also pasted OVER the original string)
- quit script
The script works fine (I can provide the complete listing, if anyone is interested) - but I would like to improve it, such as that it runs as a stay-open script, doing the following:
- when started, the script would ask the user to select some options, such as:
- name and location of glossary TXT file
- which type of matching to use (“exact match” or e.g. “regex-type”)
- whether to also show the results as a notification
- etc…
- then, after the settings have been entered (in a custom dialog with some checkboxes, etc.), the script would be hidden and wait for input - as usual, by a keyboard shortcut (?)
(i.e. I want to set the options just once, when the script is started!)
So, I know this could be done by actually having TWO scripts:
- turn my existing glossary script into a main (stay-open) script, as described above, which would do the initial options setup via dialog as described above, and a separate handler for the rest of the stuff (searching and returning the result, etc. - which is the script as I have it now)
- second script, which is started via keyboard shortcut, which would just copy the selected text/string and send it to the first (stay-open) script handler, which will do its stuff and return the result…
But, I would like to have my glossary script available to others for download, and having this in two scripts, setting up the keyboard shortcut, etc., might be a bit complicated for non tech-savvy users… It would be better to have just ONE script / Automator workflow…
Is it possible to have the process as I described it above (initial setup of options which is done only once, when the stay-open script is started) in just ONE script?
I guess I would need a possibility to invoke only a certain part (handler) of the stay-open script via a keyboard shortcut…
But, from the information I managed to find so far, it does not seem that this is possible - i.e. to have a keyboard shortcut interact directly with a handler of a stay-open script…
Is there a way this could be done within a single script - or do I have to resort to having two scripts, as I described above?
Thanks in advance for any help…
Denis
Model: Mac Mini
AppleScript: 2.7
Browser: Firefox 68.0
Operating System: macOS 10.14