You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Automator

Automator not consistant...


time stamp (Quick Action)

on run {input, parameters}

set thetime to (do shell script "date '+%nT: %l:%M %p %n ' ") as string

tell application "System Events"

keystroke thetime

end tell

end run



type the date (Quick Action)

on run {input, parameters}

set thedate to (current date) as string

tell application "System Events"

keystroke thedate

end tell

end run




System Preferences...Keyboard...Shortcuts...Services...General...

timestamp ⌃⎇⌘T

type the date ⌃⎇⌘D





T: 9:12 AM

text goes here


Tuesday, October 5, 2021 at 9:12:43 AM

text goes here


...here the time didn't appear!


Tuesday, October 5, 2021 at 9:13:36 AM ...yet the date does!


...still no time here...


Tuesday, October 5, 2021 at 9:14:09 AM ...yet the date does again!


...still no time here...


...what is the problem with this?????


I started a new note and did time first, then date...


ˇÚ  9Ú15 Å 

 Tuesday, October 5, 2021 at 9:15:19 AM

T: 9:15 AM

T: 9:15 AM


...this was the output to the page!!!!


iMac Line (2012 and Later)

Posted on Oct 5, 2021 7:26 AM

Reply
Question marked as Top-ranking reply

Posted on Oct 6, 2021 11:40 AM

I recreated and implemented your scripts, and I'm 99% sure the problem is best characterized as user error.


Let me explain.


Consider keystroke as being dumb. It just simulates the keypresses corresponding to the characters in the string, and does so as quickly as it can.


I can reproduce your problem by holding the modifier keys longer than needed.


What's happening is that you:


  1. Hold the modifier keys
  2. Type the appropriate character to invoke the script
  3. Release the character key
  4. Release the modifier keys


What I think is happening is that the script is firing off immediately after you type the character key (step 3) and it is blindly typing the characters before the modifier keys are released (step 4), and so the application is interpreting it as a sequence of further modifier keystrokes, most specifically the option key is probably leading to the spurious characters.


The results do vary a bit, depending on the frontmost application at the time the actions are invoked. The only consistent way I could get it to work is to be consciously brief in how long I hold the modifier keys for.


I don't see a simple way around this. It is possible to invoke keystroke with modifiers, but I can't see how to keystroke without modifiers, regardless of what the keyboard is doing.

4 replies
Question marked as Top-ranking reply

Oct 6, 2021 11:40 AM in response to anony194

I recreated and implemented your scripts, and I'm 99% sure the problem is best characterized as user error.


Let me explain.


Consider keystroke as being dumb. It just simulates the keypresses corresponding to the characters in the string, and does so as quickly as it can.


I can reproduce your problem by holding the modifier keys longer than needed.


What's happening is that you:


  1. Hold the modifier keys
  2. Type the appropriate character to invoke the script
  3. Release the character key
  4. Release the modifier keys


What I think is happening is that the script is firing off immediately after you type the character key (step 3) and it is blindly typing the characters before the modifier keys are released (step 4), and so the application is interpreting it as a sequence of further modifier keystrokes, most specifically the option key is probably leading to the spurious characters.


The results do vary a bit, depending on the frontmost application at the time the actions are invoked. The only consistent way I could get it to work is to be consciously brief in how long I hold the modifier keys for.


I don't see a simple way around this. It is possible to invoke keystroke with modifiers, but I can't see how to keystroke without modifiers, regardless of what the keyboard is doing.

Oct 5, 2021 10:52 AM in response to anony194

I'm missing something here.


I see your scripts, and understand what you're trying to do. But I can't see how your scripts translate into the second part of your post showing the output. I have no way of knowing which keystroke/script you executed to know what you expect to see vs. what you actually see.


I get there's some inconsistency between different invocations, but I can't tell which one is being called at any moment to be able to triage this.

Oct 6, 2021 10:51 AM in response to Camelot

Update 10/6/21




…hope this helps clear up questions…




I pressed:  ⌃⎇⌘T


This was returned:  T:  9:12 AM 


I typed: text goes here


I pressed:  ⌃⎇⌘D


This was returned:  Tuesday, October 5, 2021 at 9:12:43 AM


I typed: text goes here


I pressed:  ⌃⎇⌘T


...here the time didn't appear!


I pressed:  ⌃⎇⌘D


This was returned:  Tuesday, October 5, 2021 at 9:13:36 AM


I pressed:  ⌃⎇⌘T


...still no time here...


I pressed:  ⌃⎇⌘D


This was returned:  Tuesday, October 5, 2021 at 9:14:09 AM


I pressed:  ⌃⎇⌘T


...still no time here...


Soooo,


...what is the problem with this tune stamp action?






I started a completely new note and did time first, then date...


I pressed:  ⌃⎇⌘T


This was returned: ˇÚ  9Ú15 Å 


I pressed:  ⌃⎇⌘D


This was returned: Tuesday, October 5, 2021 at 9:15:19 AM


  T:  9:15 AM 


 


  T:  9:15 AM 




...this was the output to the page!!!!




It was as if the previous un-returned time stamps were stacked up in a buffer, and the date stamp produced the date and the two ‘stored in buffer’ time stamps…


I have NO IDEA what the ‘gibberish’ is from…




Hope this helps.




Bob

Oct 6, 2021 12:20 PM in response to Camelot

Wednesday, October 6, 2021 at 2:13:40 PM - got response from Camelot after I sent more details as to what my sequence was like. Basically, the answer is type the character sequence very quickly and it should work. The date command worked as seen at the beginning of this paragraph. Now, to test how this has an effect on the time stamp...

T: 2:16 PM

...sure enough...the quick action of the keys produced the correct time mark seen above! I will do one more test just to make sure of this...here goes...

T: 2:17 PM

...PERFECT!!!

Camelot is a genius! Thanks so much for the fast responses and solution to my dilemma.

Automator

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.