How to use Text Expander when pasting from Shortcut

Discussion, questions and support.
Post Reply
FastM
Posts: 21
Joined: Oct 24th, ’14, 04:25

Post by FastM » Jan 15th, ’19, 17:27

Hello

I hope someone can help.

I have a Text Expander phrase file in the following format that I use to modify dates:
Abbreviation Substitute
/01 January 2018
/02 February 2018
etc. etc

So, if I input a date as 05/09 it is converted to 05 September 2018. All this works perfectly.

However, what I would like to be able to do is copy a date in the format dd/mm/2018 and then paste into a document and at the same time convert it to the format dd Month 2018.

The above phase file would work (or I imagine it would) if the text was typed into the new document as individual characters but does not appear to when the text is pasted.

I therefore wondered whether there was a way to emulate typing the text into the document rather than pasting it or whether there is another simpler solution to the problem.

Many thanks

FastM
User avatar
Marko
Posts: 1719
Joined: Mar 2nd, ’13, 21:02

Post by Marko » Jan 15th, ’19, 17:40

FastKeys is sending the substitute text as individual characters as you would type them on the keyboard unless the clipboard send is enabled in Preferences/Text Expander/Advanced.

I'm not sure what exactly would you like to achieve, for converting the date format you would need to make a script - let me know the exact steps and will try to help.
FastM
Posts: 21
Joined: Oct 24th, ’14, 04:25

Post by FastM » Jan 16th, ’19, 01:01

Hi Marko

Many thanks for the rapid response and apologies for failing to explain things clearly enough.

As part of my invoicing process I need to copy the date from the date field in an Outlook Calendar Appointment (which is in the format "Wed 31/10/2018") and add it to the text box below in the format "Wednesday 31 October 2018".

At the moment I type it manually with a little help from a Text Expander phrase file. I simply type the letters "Wed" followed by the "space key" and this expands into the word "Wednesday ". I then type 31/10 and this expands with another phrase file into "31 October 2018". All of which is a help but I would like to remove the typing completely.

To do this I have created a simple Shortcut Macro that can copy the date from the date field in Outlook to the clipboard, then tab down to the text box below and then paste the text from the clipboard.

Send, {Tab}^c{Tab 9}^v

What I was hoping is that as the text (e.g."Wed") is pasted into the text box it would be converted by the Text Expander phrase files into the word "Wednesday". In other words I was expecting the Text Expander to expand the pasted text in exactly the same was as if I had typed it myself. Unfortunately, it seems that when text is pasted by the macro it is ignored by the Text Expander.

I hope this is a little clearer and that you can suggest what, if anything, I might be doing wrong.

I realise that this could probably be done with a full AutoHotKey script but was trying for something quick and easy based on what I was already doing.

Many thanks
User avatar
Marko
Posts: 1719
Joined: Mar 2nd, ’13, 21:02

Post by Marko » Jan 16th, ’19, 20:34

Try this (Type: Command):

Code: Select all

Send, {Tab 2}^c
sleep, 100
date:=Clipboard
date:=SubStr(date, InStr(date, " ")+1)
StringSplit, s, date, /
FormatTime, Output, % s3 s2 s1, LongDate
Send, {Tab 9}%Output%
You may need to adjust the number of tabs and a sleep if needed.
FastM
Posts: 21
Joined: Oct 24th, ’14, 04:25

Post by FastM » Jan 17th, ’19, 02:10

Marko - that's very kind. Wasn't what I was expecting but works perfectly and taught me a lot

I actually wanted the output to include the day of the week (e.g. Monday 31 December 2018) so made a slight modification

Send, +{Tab 7}^c ; +{Tab} sends Shift + Tab
sleep, 100
date:=Clipboard
StringSplit, s, date, / " " ; splits string at either a space or a /
FormatTime, Output, % s4 s3 s2 s1, dddd d MMMM yyyy
Send,{Tab 8}%Output% {Enter} {Enter}

Seems to work with or without the "s1" in the penultimate line.

For future reference and out of curiosity am I to assume that the Text Expander won't expand text pasted from a Command shortcut (which is what I was originally tying to do) ?
User avatar
Marko
Posts: 1719
Joined: Mar 2nd, ’13, 21:02

Post by Marko » Jan 17th, ’19, 22:12

By default, commands are never triggered by keystrokes produced by FastKeys. This avoids the possibility of an infinite loop where commands trigger each other over and over.

By the way, your usage of StringSplit is incorrect, just use my script and only change "LongDate" to "dddd d MMMM yyyy" to change the format.
https://autohotkey.com/docs/commands/StringSplit.htm
https://autohotkey.com/docs/commands/FormatTime.htm
Post Reply