• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Create a script for Keyboard Shortcut Hotkey that types common word or sentence

New Here ,
Feb 23, 2017 Feb 23, 2017

Copy link to clipboard

Copied

Is there a way to write a script that will assign a hotkey to a keyboard shortcut whereby pressing it will type out a common word or sentence.  For instance, in my ad agency we use the phrase "Selected Vtys.," on nearly every item advertised, but rather than spell it out we'd like to be able to simply press Ctrl + (a letter) to write out the entire phrase.

TOPICS
Scripting

Views

2.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

People's Champ , Feb 23, 2017 Feb 23, 2017

A short script will insert any phrase you want:

try{

     app.selection[0].contents = "my phrase";

}

catch(e){}

Save that as a script, and assign any shortcut you want to it...

Votes

Translate

Translate
People's Champ ,
Feb 23, 2017 Feb 23, 2017

Copy link to clipboard

Copied

A short script will insert any phrase you want:

try{

     app.selection[0].contents = "my phrase";

}

catch(e){}

Save that as a script, and assign any shortcut you want to it...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 23, 2017 Feb 23, 2017

Copy link to clipboard

Copied

Thank you!  I knew it must be something simple.  I'm not super fluent in coding so I wasn't exactly sure what codes to input but that code worked!  Thanks a lot TAW and everyone!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 23, 2017 Feb 23, 2017

Copy link to clipboard

Copied

Hey TAW,
Is there any code to force the Cursor to the end of the line after this text is entered?  Much appreciated.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Feb 24, 2017 Feb 24, 2017

Copy link to clipboard

Copied

jamesb64534871  wrote

Hey TAW,
Is there any code to force the Cursor to the end of the line after this text is entered?  Much appreciated.

This should do it:

try{

  app.selection[0].insertionPoints[-1].select();

     app.selection[0].contents = "my phrase";

}

catch(e){}

Ariel

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 23, 2017 Feb 23, 2017

Copy link to clipboard

Copied

Hi James,

what can be done is a list of phrases.

Imagine a two-column table:

In the first column goes the short form in the second column goes the corresponding long form.

A script could know the text file holding the pairs of phrases. One pair of phrases is divided by a unique string. Not a tab character, because you could need a tab as part of a short formed or long formed phrase. Maybe the divider could be something like that: $§$. Something you'd never type or use as a short form phrase.

If you are pressing a KBSC the script will start.

It will look up the text of your current insertion point and would read out the text left from it.

That contents would be analyzed and searched in the text file. If found the long form right from the $§$ would replace the short form of the found phrase.

The script would be an ordinary ExtendScript script file available in your Scripts panel of your InDesign.

As soon it is installed it is available for defining a KBSC for executing it.

So yes, that could be done.

Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 23, 2017 Feb 23, 2017

Copy link to clipboard

Copied

Hi!

This can be done directly in InDesign! Sample: I type "wx" and a space …

Capture d’écran 2017-02-23 à 21.51.51.png

Capture d’écran 2017-02-23 à 21.52.00.png

Capture d’écran 2017-02-23 à 21.52.09.png

(^/) 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 23, 2017 Feb 23, 2017

Copy link to clipboard

Copied

Hi Obi-wan,

yes. I know that are some system tools around that can contribute some strings.

Also automatic text correction comes to my mind with exception lists…

All built in with InDesign. But someone has to maintain and install the lists.

But what is speaking for a script then?
One could implement logics, if else clauses you cannot build with exception lists.

Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 23, 2017 Feb 23, 2017

Copy link to clipboard

Copied

Uwe,

Play with "auto-correction" is so simple!  Just need to modify the .xml file with a text editor!

Capture d’écran 2017-02-23 à 23.13.56.png

Capture d’écran 2017-02-23 à 23.14.49.png

Capture d’écran 2017-02-23 à 23.15.08.png

Capture d’écran 2017-02-23 à 23.16.10.png

Capture d’écran 2017-02-23 à 23.16.24.png

Capture d’écran 2017-02-23 à 23.19.08.png

I've just typed:

"uw" + "space" + "carriage-return" + "aw" + "space" + "carriage-return" + "ow" + "space" + "carriage-return"

Capture d’écran 2017-02-23 à 23.19.39.png

The company "Geek" could do it and finally send all this .xml file! …

Cool! 

(^/)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 24, 2017 Feb 24, 2017

Copy link to clipboard

Copied

Hi Obi,

I just tried this trick but it's not working.

I've added:

<wordpair misspelled="transtibial" corrected="trans-tibial"/>

  <wordpair misspelled="transfemoral" corrected="trans-femoral"/>

I restart InDesign but it doesn't recognise the spelling.

Autocorrect in on, I can check by typing "about" and it changes to "about".

Do you have any ideas?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 24, 2017 Feb 24, 2017

Copy link to clipboard

Copied

Nevermind, I had the xml as a shortcut on my desktop and for some reason it wasn't updating the original.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 24, 2017 Feb 24, 2017

Copy link to clipboard

Copied

Maybe I'm wrong but the true problem with the use of a script is that you'll need to "manually" associate a shortcut to it to play it quickly! … and I'm not sure you can't do it automatically! 

Good luck if scripts dozens on computers dozens!

(^/)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 24, 2017 Feb 24, 2017

Copy link to clipboard

Copied

Obi-wan Kenobi

I have noticed that the xml autocorrect doesn't recognise spaces in between misspelled words.

For example:

It changes water-proof to waterproof

but won't change

water proof to waterproof.

Here's the xml:

<wordpair misspelled="water proof" corrected="waterproof"/>

  <wordpair misspelled="water-proof" corrected="waterproof"/>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 24, 2017 Feb 24, 2017

Copy link to clipboard

Copied

Hi Jake,

I did not use the autocorrect feature before, so thank you for this finding.

Hm. And how about special characters of other sort?
Could be a white space character expressed as something like an HTML entity?

&ensp; => en space

&emsp; => em space

&thinsp; => thin space

  => non breaking space

Or something like that for a simple blank?

&#0020;

Perhaps also this?

&#20;

But if that would work,

we also have to care for special characters like:

& # ; etc.pp.

Regards,

Uwe

// EDIT:

The forum software converted my entity for a non breaking space to an actual non-breaking-space.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 09, 2017 Mar 09, 2017

Copy link to clipboard

Copied

LATEST

Hi Laubender,

I've done a few tests and nothing seems to preserve the whitespace.

I imagine it's something to do with the InDesign XML parser or the XSLT.

If you find anything I'd be interested

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines