• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Persisting Changes to Native MacOS Text Replacement
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Persisting Changes to Native MacOS Text Replacement


  • Subject: Persisting Changes to Native MacOS Text Replacement
  • From: John Garrigues via AppleScript-Users <email@hidden>
  • Date: Sat, 19 Jun 2021 20:20:15 -0700
  • Resent-date: Sat, 19 Jun 2021 21:17:15 -0700
  • Resent-from: John Garrigues <email@hidden>
  • Resent-message-id: <email@hidden>
  • Resent-to: email@hidden

This AppleScript updates a Text Replacement in System
Preferences/General/Keyboard/Text that contains the current date. I want to use
it across multiple iOS devices spanning the Apple ecosystem so I am doing a
Keyboard/Text Replacement on my Mac and allow it to propagate - I'll use
Keyboard Maestro to scheduled the updates for just after midnight.

I plan to refactor and do a more deliberate match of names & variables after I
get an MVP working. This script makes the change on a positional basis (i.e.,
it updates the value field of the first name:value key pair, but I can't get
the change to stick. When System Preferences closes, the value reverts back to
what it was before I ran the script.

Can anyone suggest a way to "save" the System Preferences/General/Keyboard/Text
Replacement modification? Is there something I’m missing in the AppleScript?

> use AppleScript version "2.4" -- Yosemite (10.10) or later
> use scripting additions
>
> -- get the current date into today
> set today to short date string of (current date)
> set [_month, _day, _year] to [month, day, year] of date today
>
> -- format today so it will look like YYYY-MM-DD
> set _day to _day * 1 --> 3
> set _day to text -1 thru -2 of ("0" & _day) --> "03"
> set _month to _month * 1 --> 3
> set _month to text -1 thru -2 of ("0" & _month) --> "03"
> set _year to _year * 1 --> 5
> set _year to text -1 thru -4 of ("0" & _year)
> set the text item delimiters to "-"
> set today to {_year, _month, _day} as string
> set fullDateToday to today as string
>
> -- swap out the "With" text field in the first value row of System
> Preferences/Keyboard/Text
> tell application id "com.apple.systempreferences"
>       reveal anchor "Text" of pane id "com.apple.preference.keyboard"
>       activate
> end tell
>
> tell application id "com.apple.systemevents"
>       tell application process "System Preferences"
>               tell window "Keyboard"
>                       tell tab group 1
>                               tell scroll area 1
>                                       tell table 1
>                                               tell row 1
>                                                       tell UI element 2
>                                                               set value of
> text field 1 to today as text
>                                                       end tell
>                                               end tell
>                                       end tell
>                               end tell
>                       end tell
>               end tell
>       end tell
> end tell

Thanks in advance for any direction you can give me on how to make the change
stick.

John G


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Persisting Changes to Native MacOS Text Replacement
      • From: Axel Lüttgens via AppleScript-Users <email@hidden>
  • Prev by Date: Re: How to create a Calendar event on a specific day of next month?
  • Next by Date: Re: Persisting Changes to Native MacOS Text Replacement
  • Previous by thread: Re: How to create a Calendar event on a specific day of next month?
  • Next by thread: Re: Persisting Changes to Native MacOS Text Replacement
  • Index(es):
    • Date
    • Thread